【发布时间】:2020-10-17 19:27:00
【问题描述】:
我已经训练了一个对货币进行分类的 cnn 模型。在训练结束时,该模型似乎在训练和验证数据集方面表现得非常好。最终准确度为:
Epoch 00020: saving model to model_weights.h5
112/112 [==============================] - 243s 2s/step - loss: 0.3176 - accuracy: 0.8881 - val_loss: 0.3223 - val_accuracy: 0.9014
训练准确率为 88.81%,验证准确率为 90.14%。 但是当测试时间到来时,该模型的表现很糟糕。它甚至无法对单个正确的图像进行分类。对于每张图片,预测结果是:
[0. 0. 0. 0. 0. 0. 0. 1.]
有 8 节课。对于每张图像,只有这个是预测的。我使用的代码是用于测试的代码,是我从 Coursera 的 Tensorflow 专业复制的代码。目标大小也是正确的。
for fn in uploaded.keys():
path = fn
img = image.load_img(path, target_size=(150, 150))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
print (images.shape)
classes = model.predict(images, batch_size=10)
print(fn)
print(classes.squeeze())
结果数组应该是有序的:
['10', '100', '20', '200', '2000', '50', '500', 'Background']
根据模型,它正在对所有图像“背景”进行分类。
【问题讨论】:
-
使用 dropout 总是有帮助的。防止过拟合。
标签: python tensorflow machine-learning conv-neural-network