问题描述
我正在训练如何运行 tf.config.run_functions_eagerly(True)
行,但出现错误
I am training to run the line tf.config.run_functions_eagerly(True)
but I get the error
AttributeError: module 'tensorflow' has no attribute 'config'
我的Python版本是 3.9.2
,我正在使用Tensorflow 1.8.0
和Keras 2.1.5
.我该如何克服这个错误?
My version of Python is 3.9.2
, and I am using Tensorflow 1.8.0
, and Keras 2.1.5
. How can I get past this error?
推荐答案
急切执行是在 tf
版本2中引入.您正在使用 tf
<2个版本.请参见此处.仅供参考, tf 1.x
使用 Graph 执行,而 tf 2.x
引入了 Eager 和 Graph模式.急切执行模式在 tf 2.x
中设置为默认设置.
Eager execution is introduced in tf
version 2. You're using tf
< 2 version. See here. FYI, tf 1.x
use Graph execution whereas tf 2.x
introcuded Eager along with Graph mode. The Eager execution mode is set as default in tf 2.x
.
在 tf 1.15.1
tf.config.run_functions_eagerly(True)
AttributeError: module 'tensorflow' has no attribute 'config'
要在 tf 1.x
中启用渴望模式,您需要执行以下操作
To enable eager mode in tf 1.x
, you need to do it as follows
# Tested on tf 1.15.1
import tensorflow as tf
tf.enable_eager_execution()
tf.executing_eagerly() # True
在 tf.2.4.1
中,它是默认值.请注意,尽管在 tf 2.x
中将eager模式设置为默认模式,但仍有一些功能在 Graph 模式下运行.因此,您可以完全禁用eager模式,也可以全部设置它.要禁用eager模式或在 tf 2.x
中的所有情况下启用它,您需要设置
In tf.2.4.1
, it comes by default. Please note, though in tf 2.x
eager mode is set as default, there still are some functionalities that are run in Graph mode. So, you can either disable eager mode completely or set it for all. To disable eager mode or enable it for all cases in tf 2.x
, you would need to set
# Disables eager execution.
tf.compat.v1.disable_eager_execution()
# Disables eager execution of tf.functions.
tf.config.run_functions_eagerly(False)
or
# Enable eager execution of tf.functions.
tf.config.run_functions_eagerly(True)
这篇关于在Python 3中运行`tf.config.run_functions_eagerly(True)`吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!