【问题标题】:Keras VGGFace extracting featuresKeras VGGFace 提取特征
【发布时间】: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


    【解决方案1】:

    你不应该在那里使用utils.decode_predictions(preds),因为它只是用于分类。可以在这里查看函数的定义https://github.com/rcmalli/keras-vggface/blob/master/keras_vggface/utils.py#L66

    如果要打印功能,请使用print('Predicted:',preds)

    【讨论】:

      猜你喜欢
      • 2016-12-05
      • 2017-09-06
      • 2017-07-28
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2011-07-25
      相关资源
      最近更新 更多