首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >问题检索值decode_predictions`需要一批预测

问题检索值decode_predictions`需要一批预测
EN

Stack Overflow用户
提问于 2021-03-17 22:30:20
回答 1查看 32关注 0票数 0

我有一个预先训练的模型,试图删除一个层,并在新模型上执行预测。然而,检索错误。

代码语言:javascript
复制
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])

错误

代码语言:javascript
复制
  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)
EN

回答 1

Stack Overflow用户

发布于 2021-03-17 22:37:40

你的神经网络没有输出层。decode_predictions不能解码卷积层的输出,这是您执行include_top=False时所得到的。执行以下操作:

代码语言:javascript
复制
model = applications.VGG16(include_top=True, input_shape=(224, 224, 3), 
                           weights='imagenet')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66675147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档