RuntimeError: tf.placeholder() is not compatible with eager execution.(亲测有效)
程序员文章站
2022-06-15 13:52:53
...
今天运行Tensorflow时,出现以下错误:
RuntimeError: tf.placeholder() is not compatible with eager execution.
原因是下面这个语句:
x = tf.compat.v1.placeholder(tf.float32, [None, 784])
这个语句需要在session前定义,在session中执行,但在使用T的ensorFlow 2.0及以上版本中,默认情况下开启了紧急执行模式,即定义即执行。
所以,我们需要在上面的语句前定义一下它不着急执行,有两种解决方案:
方案一:
添加 tf.compat.v1.disable_eager_execution(),即:
tf.compat.v1.disable_eager_execution()
x = tf.compat.v1.placeholder(tf.float32, [None, 784])
方案二:
添加tf.compat.v1.disable_v2_behavior(),即:
tf.compat.v1.disable_v2_behavior()
x = tf.compat.v1.placeholder(tf.float32, [None, 784])
上一篇: 解决tf2 ValueError: Tensor‘s shape (4, 4, 1, 16) is not compatible with supplied shape (4, 4, 3, 16)
下一篇: DOM尺寸,DOM元素位置
推荐阅读
-
RuntimeError: tf.placeholder() is not compatible with eager execution.
-
RuntimeError: tf.placeholder() is not compatible with eager execution.和没有placeholder函数解决方法
-
RuntimeError: tf.placeholder() is not compatible with eager execution.解决方法
-
RuntimeError: tf.placeholder() is not compatible with eager execution.(亲测有效)