无法在 windows7 机器上的 Tensorflow 1.5 中使用 eager execution

Can't use eager execution in Tensorflow 1.5 on windows7 machine

问题

cant use eager execution in tensorflow version 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: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type. from ._conv import register_converters as _register_converters Traceback (most recent call last): File "D:/Users/hello/PycharmProjects/crimeBuster/main.py", line 6, in tf.enable_eager_execution() AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

版本

import tensorflow as tf
print(tf.__version__)
# 1.5.0

回到 version 1.5,eager execution 仍然在贡献的包中,所以你需要明确地导入它;正确的用法是:

import tensorflow as tf
import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()

此外,请记住:

For eager execution, we recommend using TensorFlow version 1.8 or newer.

(来自Github page

版本 1.7 是命令 tf.enable_eager_execution() 可用的第一个版本,即急切执行已从 contrib 中移出(参见 v1.7 changes)。