Python Tensorflow:无法将提要索引键解释为Tensor

Python Tensorflow:无法将提要索引键解释为Tensor,python,typeerror,tensorflow2.0,Python,Typeerror,Tensorflow2.0,我已经在CIFAR10上训练了一个模型,我想得到输入的梯度。因此,我按如下方式运行代码: tf.compat.v1.disable_eager_execution() print(tf.__version__) x = model.input y = model.output grad = tf.gradients(y,x)[0] sess = tf.compat.v1.Session() result = sess.run(grad,feed_dict={x:train_images[

我已经在CIFAR10上训练了一个模型,我想得到输入的梯度。因此,我按如下方式运行代码:

tf.compat.v1.disable_eager_execution()

print(tf.__version__)

x = model.input
y = model.output
grad = tf.gradients(y,x)[0]

sess = tf.compat.v1.Session()

result = sess.run(grad,feed_dict={x:train_images[0:1]})
print(result)
tf的版本是2.3.0。我得到这个错误:

TypeError:无法将feed_dict键解释为张量:张量张量(“conv2d_输入:0”,shape=(None,32,32,3),dtype=float32)不是此图的元素

请帮帮我,谢谢

尝试以下操作:
x=tf.placeholder(tf.float32,(无,32,32,3))
并在result var之前添加第二行。
sess.run(tf.global\u variables\u initializer())