Python 'module' 对象没有属性 'SummaryWriter'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41482913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:02:50  来源:igfitidea点击:

'module' object has no attribute 'SummaryWriter'

pythonpython-2.7tensorflow

提问by VansFannel

I'm using Tensorflow version 0.12.head with Python 2.7 on a linux CentOS 7 and when I run this:

我在 Linux CentOS 7 上使用带有 Python 2.7 的 Tensorflow 版本 0.12.head,当我运行这个时:

import tensorflow as tf

a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_b")
c = tf.mul(a, b, name="mul_c")
d = tf.add(a, b, name="add_d")
e = tf.add(c, d, name="add_e")
sess = tf.Session()
output = sess.run(e)
writer = tf.train.SummaryWriter('./my_graph', sess.graph)

I get this error:

我收到此错误:

AttributeError                            Traceback (most recent call last) <ipython-input-6-29c037e85eec> in <module>()
----> 1 writer = tf.train.SummaryWriter('./my_graph', sess.graph)

AttributeError: 'module' object has no attribute 'SummaryWriter'

I have run these two commands because there is bug issueon Github for the same problem:

我因为有错误运行这两个命令的问题在Github上的同样的问题:

>>> import six
>>> print(six.__version__)
1.10.0
>>> print(dir(six.moves.queue)) ['Empty', 'Full', 'LifoQueue', 'PriorityQueue', 'Queue', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_threading', '_time', 'deque', 'heapq']
>>> print(six.moves.queue.__file__) /usr/lib64/python2.7/Queue.pyc

I'm new in Python and in Tensorflow. Do you know how can I fix this error?

我是 Python 和 Tensorflow 的新手。你知道我该如何解决这个错误吗?

I have changed SummaryWriterwith FileWriter:

我已经改变SummaryWriterFileWriter

writer = tf.train.FileWriter('./my_graph', sess.graph)

And I get the same error but with FileWriterfunction:

我得到了同样的错误,但具有FileWriter功能:

AttributeError                            Traceback (most recent call last)
<ipython-input-8-daa50ea2b8f9> in <module>()
----> 1 writer = tf.train.FileWriter('./my_graph', sess.graph)

AttributeError: 'module' object has no attribute 'FileWriter'

I have also run it in a terminal and I get the same result:

我也在终端中运行它,我得到了相同的结果:

[VansFannel@localhost ~]$ python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:95] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
>>> a = tf.constant(5, name="input_a")
>>> b = tf.constant(3, name="input_b")
>>> c = tf.mul(a, b, name="mul_c")
>>> d = tf.add(a, b, name="add_d")
>>> e = tf.add(c, d, name="add_e")
>>> sess = tf.Session()
>>> output = sess.run(e)
>>> writer = tf.train.FileWriter('./my_graph', sess.graph)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'FileWriter'
>>> 

回答by l'L'l

tf.train.SummaryWriteris deprecated, instead use tf.summary.FileWriter.

tf.train.SummaryWriter已弃用,请改用tf.summary.FileWriter.

? Adding Summaries to Event Files

? 将摘要添加到事件文件

It will be removed after 2016-11-30. Instructions for updating: Please switch to tf.summary.FileWriter. The interface and behavior is the same; this is just a rename.

它将在 2016-11-30 之后移除。更新说明:请切换到tf.summary.FileWriter. 界面和行为是一样的;这只是一个重命名。

<TF Official Migration Page> ?? includes all current deprecated/renamed functions ??

< TF Official Migration Page> ?? 包括所有当前已弃用/重命名的函数?

回答by Salvador Dali

In a new version of TF, all summary functions were renamed.

在新版本的 TF 中,所有汇总函数都被重命名为.

Summary functions have been consolidated under the tf.summarynamespace.

汇总函数已合并到tf.summary命名空间下。

 Deprecated                                               Replacement
----------------------------------------------------------------------------------
 tf.audio_summary                                         tf.summary.audio
 tf.contrib.deprecated.histogram_summary                  tf.summary.histogram
 tf.contrib.deprecated.scalar_summary                     tf.summary.scalar
 tf.histogram_summary                                     tf.summary.histogram
 tf.image_summary                                         tf.summary.image
 tf.merge_all_summaries                                   tf.summary.merge_all
 tf.merge_summary                                         tf.summary.merge
 tf.scalar_summary                                        tf.summary.scalar
 tf.train.SummaryWriter                                   tf.summary.FileWriter
----------------------------------------------------------------------------------

回答by Ken M

i had the same problem...i am using pything 3.5.2...see solution below...hope this works for you..it did for me (it will create a log in your tmp folder):

我遇到了同样的问题...我正在使用 pything 3.5.2...请参阅下面的解决方案...希望这对您有用...它对我有用(它将在您的 tmp 文件夹中创建一个日志):

import tensorflow as tf
a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_a")
c = tf.multiply(a,b, name="mul_c")
d = tf.add(a,b, name="add_d")
e = tf.add(c,d, name="add_e")

sess = tf.Session()
sess.run(e)
output = sess.run(e)

writer = tf.summary.FileWriter('/tmp/tensorflow_logs', graph=sess.graph)

print(sess.run(e))