我使用VGG16和keras进行迁移学习(我的新模型中有7个类),因此我想使用内置解码预测方法输出模型的预测。但是,使用以下代码:
preds = model.predict(img)
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, 7)
现在我想知道为什么在我的再培训模式中只有7节课的时候会有1000人。在
我在stackoverflow(Keras: ValueError: decode_predictions expects a batch of predictions)上发现了一个类似的问题 )建议在模型定义时包含“inlcude_top=True”,以解决此问题:
^{pr2}$我已经试过了,但是它仍然不起作用——给了我和以前一样的错误。任何关于如何解决这个问题的提示或建议都是非常感谢的。在
我怀疑您使用的是一些预先训练过的模型,例如resnet50,并且您正在导入
decode_predictions
,如下所示:解码预测将一个(num_samples,1000)概率数组转换为原始imagenet类的类名。在
如果你想在7个不同的班级之间进行横向学习和分类,你需要这样做:
^{pr2}$在拟合模型并计算预测之后,您必须使用imported
decode_predictions
将类名手动分配给output number,而不使用相关问题 更多 >
编程相关推荐