参考文献: image-classification-using-tensorflow-on-docker-windows
第一个报错
ModuleNotFoundError: No module named 'tensorflow.contrib'
解决办法:tenfowflow从2.2.0版本降到1.14:
docker pull tensorflow/tensorflow:1.14.0
第二个报错
下载模型失败
Downloading TF-Hub Module 'https://tfhub.dev/google/imagenet/inception_v3/feature_vector/3'
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
网上搜索到这个:记录一次使用inception-v3迁移学习训练自己的图片分类器
按照文章说法,下载新的 retrain.py
查看这个retrain.py,看到它是从这个链接 http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz 下载模型文件
重新训练,成功。模型文件输出在:
root@200adb6677d9:/image_classification/shipping_container# ls -l
total 85444
drwxr-xr-x 2 root root 36864 May 31 10:12 no
-rw-r--r-- 1 root root 87436546 May 31 10:20 retrained_graph.pb
-rw-r--r-- 1 root root 7 May 31 10:20 retrained_labels.txt
drwxr-xr-x 2 root root 4096 May 31 10:07 scripts
drwxr-xr-x 2 root root 4096 May 31 10:18 test_image
drwxr-xr-x 2 root root 4096 May 31 09:13 yes
第三个报错
测试模型的预测结果是否正确:
python scripts/image_label.py --graph=/image_classification/shipping_container/retrained_graph.pb --labels=/image_classification/shipping_container/retrained_labels.txt --input_layer=Mul --output_layer=final_result --image=/image_classification/shipping_container/test_image/yes1.jpg
报错了:
KeyError: "The name 'import/Placeholder' refers to an Operation not in the graph."
看stackoverflow上的解决办法,把input_layer改为Mul后成功(但不知道是什么原理理。。):
再次执行 image_label.py
输出:
yes 0.97871906
no 0.021280967
97%的概率是yes,符合预期
网友评论