[英]AttributeError: module 'tensorflow.python.training.training' has no attribute 'SummaryWriter'
[英]'module' object has no attribute 'SummaryWriter'
我在 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)
我收到此錯誤:
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'
>>>
tf.train.SummaryWriter
已被棄用,改用tf.summary.FileWriter
。
它將在 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))
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.create_file_writer('/tmp/tensorflow_logs', graph=sess.graph)
print(sess.run(e))
這對我有用。
tf.summary.create_file_writer('/pnplogs')
create_file_writer()
為給定的日志目錄(在我的例子中是pnplogs
)創建一個摘要文件pnplogs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.