首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tensorflow错误:ValueError:形状(?,)和(656,875,3)不兼容

Tensorflow错误:ValueError:形状(?,)和(656,875,3)不兼容
EN

Stack Overflow用户
提问于 2018-01-09 14:22:04
回答 1查看 770关注 0票数 2
代码语言:javascript
复制
import tensorflow as tf 

reader = tf.TFRecordReader()
filename_queue = tf.train.string_input_producer(['output/output.tfrecords'])

_,serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(serialized_example, features={
    'image_raw':tf.FixedLenFeature([], tf.string),
    'height':tf.FixedLenFeature([], tf.int64),
    'width':tf.FixedLenFeature([], tf.int64),
    'channel':tf.FixedLenFeature([], tf.int64)
    })
image = features['image_raw']
height, width = features['height'], features['width']
channel = features['channel']
decoded_image = tf.decode_raw(image, tf.uint8)
decoded_image.set_shape([656, 875, 3])

IMAGE_SIZE = 512
image = tf.image.convert_image_dtype(decoded_image, dtype=tf.float32)
destorted_image = tf.image.resize_image_with_crop_or_pad(image, IMAGE_SIZE, IMAGE_SIZE)

min_after_dequeue = 10000
batch_size = 100
capacity = min_after_dequeue + 3 * batch_size
image_batch = tf.train.shuffle_batch(
    [destorted_image], batch_size=batch_size,
    capacity = capacity, min_after_dequeue=min_after_dequeue)

with tf.Session() as sess:
    tf.initialize_all_variables().run()
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)
    for i in range(10):
        image = sess.run([image_batch])
        print(len(image))

我正在尝试运行tensorflow来处理我自己的tfrecords文件。代码:

代码语言:javascript
复制
`decoded_image.set_shape([656, 875, 3])` 

显示错误:ValueError:形状(?,)和(656,875,3)不兼容。如果我只运行代码:

代码语言:javascript
复制
print(sess.run(len(decoded_image)))

好的,它可以显示1722000。所以我认为我的to记录文件没有problem.How来处理这个bug?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-09 15:32:46

tf.decode_raw返回一维张量,并且tf.set_shape不能更改张量的维数。

请改用tf.reshape,如下所示:

代码语言:javascript
复制
decoded_image = tf.reshape(decoded_image, shape=[656, 875, 3])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48162440

复制
相关文章

相似问题

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