2

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

4

1 回答 1

3

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

于 2020-09-09T12:07:13.913 回答