AttributeError:module' tensorflow'没有属性' GraphDef'

时间:2017-12-22 17:12:49

标签: python tensorflow machine-learning

尝试在PyCharm 2017.3.1中运行以下内容:

with open('../data/UrbanSound8K/retrained_graph.pb', 'rb') as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    tf.import_graph_def(graph_def, name='')

我收到以下内容:

/anaconda/bin/python3 /Users/PycharmProjects/UrbanSound/src/recognize_sound.py
Traceback (most recent call last):
  File "/Users/PycharmProjects/UrbanSound/src/recognize_sound.py", line 12, in <module>
    graph_def = tf.GraphDef()
AttributeError: module 'tensorflow' has no attribute 'GraphDef'

以下是一些环境信息:

(tensorflow) $ python3 -c 'import tensorflow as tf; print(tf.__version__)'
1.4.0
(tensorflow) $ python -V
Python 3.6.2

提前感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

我使用

解决了
  

python36 -m pip install tensorflow-gpu == 1.14

答案 1 :(得分:1)

如果使用tensorflow 2.0,请

使用“ tf.compat.v1.GraphDef()”代替

答案 2 :(得分:1)

禁用V2行为

import tensorflow.compat.v1 as tf 
tf.disable_v2_behavior()

或使用此tf.compat.v1.GraphDef()