Подтвердить что ты не робот

Объект 'module' не имеет атрибута 'SummaryWriter'

Я использую Tensorflow версии 0.12.head с Python 2.7 на linux CentOS 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 есть ошибка issue для этой же проблемы:

>>> 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. Вы знаете, как я могу исправить эту ошибку?

Я изменил SummaryWriter на FileWriter:

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'

Я также запускаю его в терминале, и получаю тот же результат:

[[email protected] ~]$ 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'
>>> 
4b9b3361

Ответ 1

tf.train.SummaryWriter устарела, вместо этого используйте tf.summary.FileWriter.

Sum Добавление аннотаций в файлы событий

Он будет удален после 2016-11-30. Инструкции по обновлению: Пожалуйста, переключитесь на tf.summary.FileWriter. Интерфейс и поведение одинаковы; это просто переименование.

< TF Official Migration Page > ✳︎ включает все устаревшие/переименованные функции ✳︎

Ответ 2

В новой версии 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
----------------------------------------------------------------------------------

Ответ 3

У меня была та же проблема... я использую 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))