2017-01-05 19 views
22

używam Tensorflow wersji 0.12.head z Pythona 2.7 w systemie Linux CentOS 7 i gdy uruchomię to:'moduł' obiekt ma atrybut 'SummaryWriter'

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) 

otrzymuję ten błąd:

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' 

mam uruchomić te dwa polecenia, ponieważ istnieje bug issue na Github dla tego samego problemu:

>>> 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 

Jestem nowy w Pythonie i w Tensorflow. Czy wiesz, jak mogę naprawić ten błąd?

Zmieniłem SummaryWriter z FileWriter:

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

I uzyskać ten sam błąd, ale z FileWriter funkcję:

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' 

Mam również uruchomić go w terminalu i uzyskać ten sam rezultat :

[[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' 
>>> 
+0

Możliwe duplikat [Tensorflow: 'moduł' obiekt ma atrybut 'skalarne \ _summary'] (http://stackoverflow.com/questions/41066244/tensorflow-module-object-has-no -attribute-scalar-summary) –

Odpowiedz

49

tf.train.SummaryWriter jest przestarzałe, zamiast tego użyj 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.

< TF Official Migration Page> ✳︎ zawiera wszystkie aktualne nieaktualnych/przenoszone funkcje ✳︎

+0

Dzięki, ale otrzymuję ten sam błąd z 'FileWriter'. – VansFannel

+0

@VansFannel: To jest osobliwe; Myślę, że 'iPython' może mieć z tym coś wspólnego. Czy masz dostępną standardową wersję Pythona? –

+0

Nie rozumiem, co masz na myśli, mówiąc o * standardowej wersji *. Nawiasem mówiąc, używam tego kodu w notatniku Jupytera. – VansFannel

3

miałem ten sam problem ... Używam pything 3.5.2 .. .patrz rozwiązanie poniżej ... mam nadzieję, że to działa dla ciebie .. to zrobiło dla mnie (utworzy dziennik w folderze 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)) 
4

W nowej wersji TF, wszystkie summary functions were renamed.

Summary functions have been consolidated under the tf.summary namespace.

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 
----------------------------------------------------------------------------------