gpt4 book ai didi

keras - 升级tensorflow2.1后,得到 "RuntimeError: tf.placeholder() is not compatible with eager execution."

转载 作者:行者123 更新时间:2023-12-04 10:23:27 24 4
gpt4 key购买 nike

我是新来的,最近我正在用 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 之前,我可以运行模型,但现在我需要那个代码......)
有人可以帮我弄清楚吗??谢谢..

最佳答案

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

关于keras - 升级tensorflow2.1后,得到 "RuntimeError: tf.placeholder() is not compatible with eager execution.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60724146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com