def read_and_decode(self, example_serialized):
""" Read and decode binarized, raw MNIST dataset from .tfrecords file generated by MNIST.py """
features = tf.parse_single_example(
example_serialized,
features={
'image': tf.FixedLenFeature([], tf.string),
'label': tf.FixedLenFeature([self.flags['num_classes']], tf.int64, default_value=[-1]*self.flags['num_classes']),
'height': tf.FixedLenFeature([], tf.int64),
'width': tf.FixedLenFeature([], tf.int64),
'depth': tf.FixedLenFeature([], tf.int64),
})
# now return the converted data
label = features['label']
image = tf.decode_raw(features['image'], tf.float32)
image.set_shape([784])
image = tf.reshape(image, [28, 28, 1])
image = (image - 0.5) * 2 # max value = 1, min value = -1
return image, tf.cast(label, tf.int32)
评论列表
文章目录