尝试在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
提前感谢您的帮助。
答案 0 :(得分:1)
我使用
解决了python36 -m pip install tensorflow-gpu == 1.14
答案 1 :(得分:1)
使用“ tf.compat.v1.GraphDef()”代替
答案 2 :(得分:1)
禁用V2行为
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
或使用此tf.compat.v1.GraphDef()