TensorFlow2报错:tf.placeholder, is not compatible with eager execution.

当我们将TensorFlow1.x中的程序迁移到2.0+版本时,在之前1.x版本中有函数tf.placeholder(),替换成tf.compat.v1.placeholder(),运行时报如下错误:

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

解决方案:

在代码前加入下面一行即可:

tf.compat.v1.disable_eager_execution()

更多请参见博文:

https://blog.csdn.net/caoyuan666/article/details/104706756