回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我在linux CentOS 7上使用Tensorflow 0.12.head版本和Python2.7,运行时:</p>
<pre><code>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)
</code></pre>
<p>我得到这个错误:</p>
<pre><code>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'
</code></pre>
<p>我运行这两个命令是因为Github上有一个bug<a href="https://github.com/tensorflow/tensorflow/issues/1645" rel="noreferrer">issue</a>用于相同的问题:</p>
<pre><code>>>> 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
</code></pre>
<p>我是Python和Tensorflow的新手。你知道我怎样才能纠正这个错误吗?</p>
<p>我用<code>FileWriter</code>更改了<code>SummaryWriter</code>:</p>
<pre><code>writer = tf.train.FileWriter('./my_graph', sess.graph)
</code></pre>
<p>我得到了同样的错误,但是使用<code>FileWriter</code>函数:</p>
<pre><code>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'
</code></pre>
<p>我也在一个终端上运行了它,得到了相同的结果:</p>
<pre><code>[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'
>>>
</code></pre>