def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
features={
'image_raw': tf.FixedLenFeature([], tf.string),
'label_raw': tf.FixedLenFeature([], tf.string),
})
image = tf.decode_raw(features['image_raw'], tf.int16)
image.set_shape([IMAGE_HEIGHT * IMAGE_WIDTH])
image = tf.cast(image, tf.float32) * (1. / 255) - 0.5
reshape_image = tf.reshape(image, [IMAGE_HEIGHT, IMAGE_WIDTH, 1])
label = tf.decode_raw(features['label_raw'], tf.uint8)
label.set_shape([CHARS_NUM * CLASSES_NUM])
reshape_label = tf.reshape(label, [CHARS_NUM, CLASSES_NUM])
return tf.cast(reshape_image, tf.float32), tf.cast(reshape_label, tf.float32)
评论列表
文章目录