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文件。代码:
`decoded_image.set_shape([656, 875, 3])` 显示错误:ValueError:形状(?,)和(656,875,3)不兼容。如果我只运行代码:
print(sess.run(len(decoded_image)))好的,它可以显示1722000。所以我认为我的to记录文件没有problem.How来处理这个bug?
发布于 2018-01-09 15:32:46
tf.decode_raw返回一维张量,并且tf.set_shape不能更改张量的维数。
请改用tf.reshape,如下所示:
decoded_image = tf.reshape(decoded_image, shape=[656, 875, 3])https://stackoverflow.com/questions/48162440
复制相似问题