Tensorflow读取带有标签的图像时出错

Tensorflow读取带有标签的图像时出错,tensorflow,Tensorflow,我正在尝试读取一组图像和标签以进行批量培训,但我不断收到错误: TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on th

我正在尝试读取一组图像和标签以进行批量培训,但我不断收到错误:

TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use TensorFlow ops such as tf.cond to execute subgraphs conditioned on the value of a tensor.
下面是我的简化代码,它再现了错误:

import tensorflow as tf
import numpy as np

image = tf.image.decode_jpeg('C:\\Users\\Alex\\Documents\\Programing\\Python\\cs_dataset\\square.jpeg', channels = 1)
image.set_shape([15, 15, 1])
label = np.array([0, 1])
tf.convert_to_tensor(label)

ibatch, lbatch = tf.train.batch([image, label], batch_size=1)
init_op = tf.global_variables_initializer()

with tf.Session() as sess:
    init_op.run()
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    sess.run(ibatch, lbatch)
    coord.request_stop()
    coord.join(threads)
在这个例子中,我只使用了一个图像。 在这个简单的例子中,这个错误的原因是什么

一个没有帮助的相关问题:

如果要在
会话中计算多个张量
,需要将它们以数组形式传递给
获取
会话。运行(获取)


因此,将
sess.run(ibatch,lbatch)
更改为
sess.run([ibatch,lbatch])
请参阅以了解更多信息。

此错误发生在哪一行?它也应该是
sess.run([ibatch,lbatch])
@bodokaiser第16行,“sess.run(ibatch,lbatch)”。你的修复成功了,谢谢@博多凯瑟,你能把它作为一个完整的回复吗?