python - Keras 模型 evaluate() 和 predict_classes() 给出了相互矛盾的结果
问题描述
我已经使用 Keras 的 VGG16 工作了一段时间,在对我自己的 4 类数据集进行微调之后,训练似乎进展顺利,训练和验证集的准确性提高了,最后,即使使用评估model.evaluate()
也给出了很好的准确性关于测试数据。我试过confusion_matrix
了,它也显示出很好的分类结果。为了确认,我尝试使用以下方法从我的数据集中预测图像:
im = cv2.resize(frame,(image_size, image_size), interpolation = cv2.INTER_AREA)
#convert the image pixels to a numpy array
framer = img_to_array(im)
image = framer.reshape((1, framer.shape[0], framer.shape[1], framer.shape[2]))
# prepare the image for the VGG model
image = preprocess_input(image)
label = FLOW1_model.predict_classes(image, verbose=0)
我只为 1 类(0 类)加载了流帧,但只有大约 30% 的图片被正确分类,而在另一类(1 类)中,分类正确率为 50%。考虑到我训练时的准确率超过 85%,而且混淆矩阵显示出非常好的结果,我觉得这很不正常。我在网上查看了所有可能的原因,但找不到问题所在......是否有一个已知问题可以解释结果中的这种差异?
编辑:
我基本上加载没有顶部的 Keras vgg,添加我自己的分类器并像这样编译模型:
# Compile the model method 2
sgd = SGD(lr=0.00001, decay = 1e-6, momentum=0.9, nesterov=True)
model.compile(optimizer=sgd, loss='categorical_crossentropy', metrics=['accuracy'])
解决方案
据我所知,在多类输出的情况下,您不能使用 predict_classes() 方法。您是否已经尝试过:
FLOW1_model.predict(image, verbose=0)
推荐阅读
- python - 我们如何访问嵌入在 ul 和 li 标签中的锚标签链接,以使用 selenium 和 python 打开与该标签关联的链接
- javascript - PHP(SQL) Array Passing to JS using ajax
- javascript - React + d3 工具提示与图例重叠
- c - StmCubeIDE 调试 STM32F411CEU6 的问题
- laravel - 使用 Laravel Cashier 获取 Stripe 即将到来的发票行项目
- spring-boot - 在 ElasticSearch 中不使用脚本追加字符串
- ssh - proxycommand 似乎不适用于 ansible 和我的环境
- javascript - 当我们使用服务工作者时,如何在每次刷新时停止增加缓存内存
- svg - 如何使用 svgwrite 嵌入/使用 ICC 颜色配置文件?
- node.js - node-cron 时区仅在时区与机器时区相同时工作