首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tensorflow维度:必须完全定义所有形状:[TensorShape([Dimension(None),Dimension(None),Dimension(3)]),TensorShape([])

Tensorflow维度:必须完全定义所有形状:[TensorShape([Dimension(None),Dimension(None),Dimension(3)]),TensorShape([])
EN

Stack Overflow用户
提问于 2017-08-19 19:02:18
回答 1查看 4.7K关注 0票数 1

我想使用批处理在解码后从文件folder.But中读取图像,这在我使用tf.train.batch时可能会有一些问题。下面是代码。

代码语言:javascript
复制
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

错误是说我没有定义一些张量形状。我不知道如何解码我没有在正确的way.Here中使用解码是错误的。

代码语言:javascript
复制
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([])]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-19 19:43:13

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45770740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档