使用tensorflow hub再训练脚本在任何新类别的图像上重新训练的任何架构的高度不正确的预测

时间:2018-06-14 13:09:59

标签: python tensorflow convolutional-neural-network

我正在使用script对可用的花卉图像进行再培训here。我的输出是 INFO:tensorflow:Restoring parameters from /tmp/_retrain_checkpoint INFO:tensorflow:Final test accuracy = 92.5% (N=362) INFO:tensorflow:Save final result to : tf_files/retrained_graph.pb
因此,Inception V3和tfhub_module的准确度为92.5%this 但是当我用

预测图像时
python -m scripts.label_image \
    --graph=tf_files/retrained_graph.pb  \
    --image=tf_files/flower_photos/roses/568715474_bdb64ccc32.jpg \
    --input_height=299 \
    --input_width=299 \
    --input_layer='Placeholder

我的输出是

Evaluation time (1-image): 3.639s         
daisy (score=0.54625)  
tulips (score=0.18089)  
roses (score=0.17955)  
dandelion (score=0.06436)  
sunflowers (score=0.02894)

对于完美的玫瑰,它预测为雏菊。对于此花卉数据集中的几乎所有图像以及另一个数据集,都会发生这种情况。 Google Codelabs还有另一个再培训脚本。当我使用相同的花卉数据集进行重新训练时,使用这个脚本,我的准确度达到了93%,而且它也正确地预测了。

Evaluation time (1-image): 1.857s
roses (score=0.99969)
tulips (score=0.00030)
sunflowers (score=0.00001)
daisy (score=0.00000)
dandelion (score=0.00000)

那么,这两个脚本之间的区别是什么,为什么第一个脚本尽管显示出非常高的最终测试精度而错误地预测图像?

2 个答案:

答案 0 :(得分:1)

讨论和解决方案是here

答案 1 :(得分:0)

很难说确切的错误可能是什么,但我确定它不是重新训练代码。它很可能是您正在使用的测试代码。本教程中的测试代码取决于labels.txt文件,该文件用于将矢量与其对应的标签进行匹配。

每次运行retrain.py时,labels.txt可能会有所不同,我觉得在这种情况下,标签如果labels.txt的顺序错误。不确定这是否是解决方案,只是一种直觉。