def read_and_decode2(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
features={
'file_bytes': tf.FixedLenFeature([], tf.string),
})
# decode the png image
image = tf.image.decode_png(features['file_bytes'], channels=3)
# Convert to float image
image = tf.cast(image, tf.float32)
image.set_shape((IMAGE_SIZE, IMAGE_SIZE, CHANNELS))
# convert to grayscale if needed
if CHANNELS == 1:
image = tf.reduce_mean(image, reduction_indices=[2], keep_dims=True)
# normalize
image = image * (2. / 255) - 1
return image
评论列表
文章目录