Tensorflow:ImportError 无法在 retrain.py 中导入名称 graph_util

问题描述:

我从源代码编译 Tensorflow 以使用 GPU.我能够成功安装它.它能够成功运行示例 mnist convolutional.py 脚本.

I compiled Tensorflow from source to work with GPU. I was able to successfully install it. It's able to successfully run the sample mnist convolutional.py script.

但是,当我在 tensorflow/examples/image_retraining 中执行 retrain.py 脚本时,它吐出以下错误:

However, when I do the retrain.py script in tensorflow/examples/image_retraining, it spits out the following error:

Traceback (most recent call last):
  File "retrain.py", line 70, in <module>
    from tensorflow.python.client import graph_util
ImportError: cannot import name graph_util

带有命令和其他输出:

$ python retrain.py \
--bottleneck_dir=gpu_train/bottlenecks \
--model_dir=inception \
--output_graph=gpu_train/retrained_graph.pb \
--output_labels=gpu_train/retrained_labels.txt \
--image_dir categories
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.dylib locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.dylib locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.dylib locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.dylib locally
I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.dylib locally
Traceback (most recent call last):
  File "retrain.py", line 70, in <module>
    from tensorflow.python.client import graph_util
ImportError: cannot import name graph_util

有一个提交 昨天将文件 graph_util.pytensorflow.python.client 移动到 tensorflow.python.framework.

There was a commit yesterday which moved the file graph_util.py from tensorflow.python.client to tensorflow.python.framework.

奇怪的是,你有旧版本的 retrain.py 和 import from tensorflow.python.client import graph_util,但也有 graph_util.py 移动了.

It is weird that you have the old version of retrain.py with the import from tensorflow.python.client import graph_util, but have also graph_util.py moved.

无论如何,主版本 graph_util.py 是最新的(使用 from tensorflow.python.framework import graph_util)所以你应该得到最新版本(不需要再次编译,只需拉).

Anyway, the master version of graph_util.py is up to date (with from tensorflow.python.framework import graph_util) so you should get the newest version (no need to compile again, just pull).