【发布时间】:2019-10-28 14:32:02
【问题描述】:
我正在尝试使用 TensorFlow 和 Keras 从 VGGFace 模型的卷积层中提取特征。
这是我的代码:
# Layer Features
layer_name = 'conv1_2' # Edit this line
vgg_model = VGGFace() # Pooling: None, avg or max
out = vgg_model.get_layer(layer_name).output
vgg_model_new = Model(vgg_model.input, out)
def main():
img = image.load_img('myimage.jpg', target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = utils.preprocess_input(x, version=1)
preds = vgg_model_new.predict(x)
print('Predicted:', utils.decode_predictions(preds))
exit(0)
但是,在print('Predicted:', utils.decode_predictions(preds)) 行我收到以下错误:
Message=
decode_predictions需要一批预测(即 V1 的二维形状数组 (samples, 2622)) 或 (samples, 8631) for V2.找到形状为:(1, 224, 224, 64)的数组
我只想提取特征,此时不需要对图像进行分类。此代码基于https://github.com/rcmalli/keras-vggface
【问题讨论】:
标签: python tensorflow keras vgg-net