AttributeError:'module'对象没有属性'merge_all_summaries'

时间:2017-02-27 09:22:49

标签: python-2.7 tensorflow ubuntu-14.04 anaconda

Ubuntu 14.04。

Python 2.7.13 :: Anaconda custom(64位)

我安装了Tensorflow,遵循教程:https://www.tensorflow.org/install/

当我进入

  

〜/ anaconda2 / LIB / python2.7 /站点包/ tensorflow /示例/教程/ MNIST

并尝试运行已存在的python文件:

  

fully_connected_feed.py

我遇到了以下 AttributeError

:~/anaconda2/lib/python2.7/site-packages/tensorflow/examples/tutorials/mnist$ python fully_connected_feed.py 
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Extracting Mnist_data/train-images-idx3-ubyte.gz
Extracting Mnist_data/train-labels-idx1-ubyte.gz
Extracting Mnist_data/t10k-images-idx3-ubyte.gz
Extracting Mnist_data/t10k-labels-idx1-ubyte.gz
Traceback (most recent call last):
  File "fully_connected_feed.py", line 229, in <module>
    tf.app.run()
  File "/home/hok/anaconda2/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "fully_connected_feed.py", line 225, in main
    run_training()
  File "fully_connected_feed.py", line 154, in run_training
    summary_op = tf.merge_all_summaries()
AttributeError: 'module' object has no attribute 'merge_all_summaries'

但是相同的代码在其他计算机上成功运行。所以我认为这必定是我计算机中的配置问题。

我已经按照相同的步骤多次安装tensorflow并使用它来运行深度学习一段时间。但这是我第一次遇到这样的问题。

Google中有很多建议说这种类型的AttributeError可能是 python version 的问题。但事实并非如此。

4 个答案:

答案 0 :(得分:4)

https://stackoverflow.com/a/40066895/4533188中,您可以阅读类似问题的答案:答案是根据需要进行迁移。查看https://www.tensorflow.org/install/migration。你在那里看到了

- tf.merge_summary
    - should be renamed to tf.summary.merge
- tf.train.SummaryWriter
    - should be renamed to tf.summary.FileWriter

(实际上SummaryWriter也已被更改。)因此,如果您在代码之前写字,那么您应该能够解决问题

import tensorflow as tf
tf.merge_all_summaries = tf.summary.merge_all
tf.train.SummaryWriter = tf.summary.FileWriter

(我在Keras + TensorFlow: “module 'tensorflow' has no attribute 'merge_all_summaries''”中遇到了同样的问题。)

答案 1 :(得分:2)

我在队友的帮助下解决了这个问题。

这是 tensorflow版本问题。

以前计算机中的Tensorflow版本 0.12.1 。计算机中的Tensorflow版本遇到AttributeError 1.0.0 。这个新的tensorflow版本已经改变了一些 Python api ,所以AttributeError遇到了。

在这台符合AttributeError的计算机中:

:~$ python
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
>>> __tf.version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__tf' is not defined
>>> tf.__version__
'1.0.0'
>>> 

在以前的电脑中:

:~$ python
Python 2.7.13 |Anaconda 2.4.1 (64-bit)| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally
>>> tf.__version__
'0.12.1'
>>> 

答案 2 :(得分:0)

您需要更新正在运行的python文件中的depresicated Tensorflow API,即fully_connected_feed.py

查找tf.merge_all_summaries()并将其替换为tf.summary.merge_all()

目前版本的Tensorflow使用

tf.summary.merge_all()

而不是使用

的旧版本
tf.merge_all_summaries()

答案 3 :(得分:0)

这对我有用

> x
     name             prod  category
1   Alice         Hard Hat       PPE
2   Alice          Goggles       PPE
3   Alice         Bus Fare TRANSPORT
4     Bob          Goggles       PPE
5     Bob         Training  TRAINING
6 Charlie Hard Hat, Laptop       PPE