【问题标题】:Issue retrieving value decode_predictions` expects a batch of predictions问题检索值 decode_predictions` 需要一批预测
【发布时间】:2021-03-17 14:30:20
【问题描述】:

我有一个预训练模型,试图移除一个层并对新模型执行预测。但是检索错误。

model = applications.VGG16(include_top=False, input_shape=(224, 224, 3), weights='imagenet') 
layers = [l for l in model.layers]
x = layers[9].output
x = layers[11](x)
x = layers[12](x)
x = layers[13](x)
x = layers[14](x)
x = layers[15](x)
x = layers[16](x)
x = layers[17](x)
x = layers[18](x)

result_model = Model(inputs=layers[0].input, outputs=x)
img='/content/elephant.jpg'
img = image.load_img(img, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
preds = result_model.predict(x)
print('Predicted:', decode_predictions(preds, top=3)[0])

错误

  ValueError: `decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Found array with shape: (1, 14, 14, 512)

【问题讨论】:

    标签: tensorflow machine-learning keras conv-neural-network


    【解决方案1】:

    您的神经网络没有输出层。 decode_predictions 无法解码卷积层的输出,这是您在执行 include_top=False 时得到的。这样做:

    model = applications.VGG16(include_top=True, input_shape=(224, 224, 3), 
                               weights='imagenet')
    

    【讨论】:

    • 感谢@NicolasGervais,我仍在检索同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2021-06-18
    • 2017-06-14
    • 2021-03-25
    • 2018-11-16
    • 2018-08-21
    • 1970-01-01
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多