【问题标题】:After upgraded tensorflow2.1,I got "RuntimeError: tf.placeholder() is not compatible with eager execution."升级tensorflow2.1后,出现“RuntimeError: tf.placeholder() is not compatible with eager execution。”
【发布时间】:2020-06-28 15:19:12
【问题描述】:

我是新来的,最近我在用tensorflow和keras学习CNN,我正在尝试运行cnn模型来训练mnist数据集,但是在我用tnesorflow 2.0升级到2.1之后,我收到了这个错误消息:

 raise RuntimeError("tf.placeholder() is not compatible with "

 RuntimeError: tf.placeholder() is not compatible with eager execution.

我试试这个代码

tf.compat.v1.disable_eager_execution()

接下来,

##build input layer

with tf.compat.v1.name_scope('Input_Layer'):
x=tf.compat.v1.placeholder("float",shape=[None, 784],name="x")
x_image = tf.compat.v1.reshape(x, [-1,28,28,1])

下面是CNN模型,所以我可以成功运行模型,但我仍然想了解为什么.... (在我升级到 2.1 之前,我可以运行模型,但现在我需要那个代码......) 有人可以帮我弄清楚吗?谢谢..

【问题讨论】:

  • Eager Execution 的重点是摆脱预建图,即占位符。

标签: keras tensorflow2.0


【解决方案1】:

在您的代码中使用这一行: tf.compat.v1.disable_eager_execution()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 2017-06-10
    • 2022-09-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多