Tensorflow - CIFAR 教程中的导入错误

Tensorflow - import error in CIFAR tutorial

最近安装tensorflow,在CIFAR教程中出现python导入错误
我正在使用 Mac OS X,仅 CPU,Python 2.7.

$ python cifar10_train.py 

Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes.
Traceback (most recent call last):
File "cifar10_train.py", line 120, in
tf.app.run()
File "/Users/sunwoo/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run
sys.exit(main(sys.argv[:1] + flags_passthrough))
File "cifar10_train.py", line 116, in main
train()
File "cifar10_train.py", line 76, in train
class _LoggerHook(tf.train.SessionRunHook):
AttributeError: 'module' object has no attribute 'SessionRunHook'

如何导入 tf.train.SessionRunHook?

看起来您正在使用 master branch of cifar10_train.py, with an older installed version of TensorFlow (0.11 or earlier). The master branch was recently modified 来使用新的 API,它在 TensorFlow 0.11 或更早版本中不可用。

有两种方法可以解决这个问题。将 TensorFlow 升级到 0.12 或更高版本,或者查看 the r0.11 branch of the TensorFlow source, and use the version of cifar10_train.py from that branch.