在Tensorflow 1.5版中不能急于执行
from __future__ import absolute_import, division, print_function
import tensorflow as tf
from tensorflow.python.client import timeline
tf.enable_eager_execution()
x = tf.random_normal([0,10000])
y= tf.random_normal([10000,1000])
res = tf.matmul(x, y)
# Run the graph with full trace option
with tf.Session() as sess:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
sess.run(res, options=run_options, run_metadata=run_metadata)
# Create the Timeline object, and write it to a json
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(ctf)
C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ h5py__init __。py:36:FutureWarning:不建议将issubdtype的第二个参数从
float
转换为np.floating
。将来,它将被视为np.float64 == np.dtype(float).type
。 从._conv导入register_converters作为_register_converters 追溯(最近一次通话): 文件“ D:/Users/hello/PycharmProjects/crimeBuster/main.py”,第6行,在 tf.enable_eager_execution() AttributeError:模块“ tensorflow”没有属性“ enable_eager_execution”
import tensorflow as tf
print(tf.__version__)
# 1.5.0
答案 0 :(得分:0)
回到version 1.5,急切的执行仍在贡献包中,因此您需要显式导入它。正确的用法是:
import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()
此外,请记住:
对于急切的执行,我们建议使用TensorFlow 1.8版或更高版本。
(来自Github page)
版本1.7是第一个使命令tf.enable_eager_execution()
可用的位置,即将急切执行的命令移出contrib
(请参阅v1.7 changes)。