有两种方法可以解决这个问题:
选项 1
这是对上述 Yaroslav 评论的扩展,比选项 2 更容易。
修改classify_image.py如下:
将tf.gfile.Exists 的所有实例替换为os.path.exists,并且
将tf.gfile.GFile 和tf.gfile.FastGFile 的所有实例替换为open
然后运行修改后的classify_image.py,它应该可以工作了。
选项 2
将 tensorflow 更新到包含 gfile 的最新版本,如 here 所述
但是,在你这样做之后,当你尝试运行classify_image.py 时,你可能会遇到以下错误:
$ python classify_image.py
>> Downloading inception-2015-12-05.tgz 100.0%
Succesfully downloaded inception-2015-12-05.tgz 88931400 bytes.
[libprotobuf ERROR google/protobuf/src/google/protobuf/io/coded_stream.cc:207] A protocol message was rejected because it was too big (more than 67108864 bytes). To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
Traceback (most recent call last):
File "classify_image.py", line 213, in <module>
tf.app.run()
File "/Users/USERNAME/.virtualenvs/mlnd/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py", line 30, in run
sys.exit(main(sys.argv))
File "classify_image.py", line 209, in main
run_inference_on_image(image)
File "classify_image.py", line 159, in run_inference_on_image
create_graph()
File "classify_image.py", line 141, in create_graph
graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message
要解决此问题,您可以按照here 所述更改源代码中的一行,然后在您的机器上重新编译 tensorflow。
选项 2 可能有点工作,尤其是如果您使用的是 Mac。