gpt4 book ai didi

python - Tensorflow ValueError : All shapes must be fully defined: [TensorShape([Dimension(None), 维度(无),维度(3)]),TensorShape([])

转载 作者:行者123 更新时间:2023-11-30 22:31:34 28 4
gpt4 key购买 nike

我想使用批处理从文件夹中读取图像。但是解码后,当我使用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([])]

最佳答案

要批处理的数据必须具有预定义的形状,在这种情况下,张量 image 没有,您需要使用 image.set_shape 指定形状或tf.image.resize_images

关于python - Tensorflow ValueError : All shapes must be fully defined: [TensorShape([Dimension(None), 维度(无),维度(3)]),TensorShape([]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45770740/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com