Tensorflow:不能将浮点数转换为张量?

数据挖掘 Python 张量流 图像识别
2022-02-13 08:39:18

我正在从事一个多位数的图像识别项目,但无论我做什么,我都会遇到某个错误。

这是我的代码示例:

graph = tf.Graph()
with graph.as_default():
    x = tf.placeholder(tf.float32, shape = (None, 66, 66, 1), name = 'x')
    y = tf.placeholder(tf.int64, shape = (None, 5), name = 'y')
    keep_prob = tf.placeholder(tf.float32, name = 'keep_prob')

...

with tf.Session(graph = graph) as sess:
    sess.run(tf.global_variables_initializer())

    for step in range(num_steps):
        offset = (step * batch_size) % (train_labels.shape[0] - batch_size)
        batch_images = train_images[offset:(offset + batch_size), :, :, :]
        batch_labels = train_labels[offset:(offset + batch_size), :]
        if step % 100 == 0:
            acc = accuracy.eval(feed_dict = {x: batch_images, y: batch_labels, keep_prob: 1.0})

当试图计算acc时,我得到了错误TypeError: Cannot interpret feed_dict key as Tensor: Can not convert a float into a Tensor

我不知道为什么我会收到这个错误。我的变量在同一个图中定义,我没有覆盖我的变量。关于导致此错误的任何想法?

0个回答
没有发现任何回复~