Python Tensorflow值错误:必须完全定义所有形状:[TensorShape([尺寸(无)、尺寸(无)、尺寸(3)])、TensorShape([])
我想使用批处理从文件夹中读取图像。但解码后,当我使用Python Tensorflow值错误:必须完全定义所有形状:[TensorShape([尺寸(无)、尺寸(无)、尺寸(3)])、TensorShape([]),python,tensorflow,Python,Tensorflow,我想使用批处理从文件夹中读取图像。但解码后,当我使用tf.train.batch时,可能会出现一些问题。下面是代码 def get_batch(image, label, batch_size, capacity): image = tf.cast(image, tf.string) label = tf.cast(label, tf.int32) input_queue = tf.train.slice_input_producer([image, label]) label = inp
tf.train.batch
时,可能会出现一些问题。下面是代码
def get_batch(image, label, batch_size, capacity):
image = tf.cast(image, tf.string)
label = tf.cast(label, tf.int32)
input_queue = tf.train.slice_input_producer([image, label])
label = input_queue[1]
image_contents = tf.read_file(input_queue[0])
image = tf.image.decode_jpeg(image_contents, channels=3)
image = tf.image.per_image_whitening(image)
image_batch, label_batch = tf.train.batch([image, label],
batch_size = batch_size,
num_threads = 8,
capacity = capacity)
label_batch = tf.reshape(label_batch, [batch_size])
image_batch = tf.cast(image_batch, tf.float32)
return image_batch, label_batch
错误是我没有定义一些张量形状。我不知道怎么做。也许我没有用正确的方式使用解码。下面是错误
Traceback (most recent call last):
File "input_data.py", line 118, in <module>
image_batch, label_batch = get_batch(image_list, label_list, BATCH_SIZE, CAPACITY)
File "input_data.py", line 90, in get_batch
capacity = capacity)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py", line 538, in batch
capacity=capacity, dtypes=types, shapes=shapes, shared_name=shared_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 453, in __init__
shapes = _as_shape_list(shapes, dtypes)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data_flow_ops.py", line 71, in _as_shape_list
raise ValueError("All shapes must be fully defined: %s" % shapes)
ValueError: All shapes must be fully defined: [TensorShape([Dimension(None), Dimension(None), Dimension(3)]), TensorShape([])]
回溯(最近一次呼叫最后一次):
文件“input_data.py”,第118行,在
image\u batch,label\u batch=get\u batch(image\u list,label\u list,batch\u SIZE,CAPACITY)
文件“input_data.py”,第90行,在get_批处理中
容量=容量)
文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/input.py”,第538行,分批
容量=容量,数据类型=类型,形状=形状,共享名称=共享名称)
文件“/usr/local/lib/python2.7/dist packages/tensorflow/python/ops/data\u flow\u ops.py”,第453行,在__
形状=_as_shape_列表(形状、数据类型)
文件“/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/data\u-flow\u-ops.py”,第71行,在形状列表中
raise VALUERROR(“必须完全定义所有形状:%s”%shapes)
ValueError:必须完全定义所有形状:[拉伸形状([尺寸(无)、尺寸(无)、尺寸(3)])、拉伸形状([])]
要批处理的数据必须具有预定义的形状,在您的情况下,tensorimage
没有,您需要使用image.set\u shape
或tf.image.resize\u images
指定形状。非常感谢。