“模块”对象没有属性“ SummaryWriter”
python
python-2.7
tensorflow
5
0

我在Linux CentOS 7上将Tensorflow版本0.12.head与Python 2.7一起使用,并且在运行此命令时:

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)

我收到此错误:

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'

我因为有错误运行这两个命令的问题在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

我是Python和Tensorflow的新手。您知道如何解决此错误吗?

我用FileWriter更改了SummaryWriter

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

而且我得到相同的错误,但具有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'

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

[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'
>>> 
参考资料:
Stack Overflow
收藏
评论
共 3 个回答
高赞 时间 活跃

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

Su 将摘要添加到事件文件

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

< TF Official Migration Page >✳︎包括所有当前不推荐使用/重命名的功能✳︎

收藏
评论

在TF的新版本中,所有摘要功能均被重命名

摘要功能已合并到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
----------------------------------------------------------------------------------
收藏
评论

我有同样的问题...我正在使用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))
收藏
评论
新手导航
  • 社区规范
  • 提出问题
  • 进行投票
  • 个人资料
  • 优化问题
  • 回答问题

关于我们

常见问题

内容许可

联系我们

@2020 AskGo
京ICP备20001863号