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

Tensorflow: ImportError cannot import name graph_util in retrain.py

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

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

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

昨天 commit 将文件 graph_util.pytensorflow.python.client 移动到 tensorflow.python.framework

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


无论如何,graph_util.pymaster version 是最新的(from tensorflow.python.framework import graph_util)所以你应该得到最新的版本(不需要再次编译,直接 pull)。