【发布时间】:2017-01-12 03:42:23
【问题描述】:
我正在尝试读取一组图像和标签以进行批量训练,但我不断收到错误消息:
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)
在这个例子中我只使用了一张图片。 在这个简单的例子中,这个错误的原因是什么?
一个没有帮助的相关问题: Tensorflow read images with labels
【问题讨论】:
-
这个错误发生在哪几行?也应该是
sess.run([ibatch, lbatch])。 -
@bodokaiser 第 16 行,“sess.run(ibatch, lbatch)”。您的修复成功了,谢谢!
-
@bodokaiser 另外,您可以将其发布为完整回复吗?
标签: tensorflow