创建placeholder时报错,是因为我安装的tensorflow为2.0+版本,而placeholder只在1.0+版本内有
X = tf.placeholder('float',[None, n_H0, n_W0, n_C0])
Y = tf.placeholder('float',[None,n_y])
按照大部分文章写的方法在import时替换成1.0版本(import tensorflow.compat.v1 as tf)仍然会报错,改为在调用时修改版本
X = tf.compat.v1.placeholder('float',[None, n_H0, n_W0, n_C0])
Y = tf.compat.v1.placeholder('float',[None,n_y])
但会报错tf.placeholder() is not compatible with eager execution.
需要在调用时额外加上这句:
tf.compat.v1.disable_eager_execution()
即,使用代码时为:
import tensorflow as tf
import numpy as np
tf.compat.v1.disable_eager_execution()
X = tf.compat.v1.placeholder('float',[None, n_H0, n_W0, n_C0])
Y = tf.compat.v1.placeholder('float',[None,n_y])
参考文献:
TensorFlow报错:tf.placeholder() is not compatible with eager execution.-CSDN博客