示例#1
0
 def parser(record):
     features = {
         'image':
         tf.FixedLenFeature([], tf.string, default_value=""),
         'label':
         tf.FixedLenFeature((),
                            tf.int64,
                            default_value=tf.zeros([], dtype=tf.int64)),
         'height':
         tf.FixedLenFeature((),
                            tf.int64,
                            default_value=tf.zeros([], dtype=tf.int64)),
         'width':
         tf.FixedLenFeature((),
                            tf.int64,
                            default_value=tf.zeros([], dtype=tf.int64))
     }
     parsed = tf.parse_single_example(record, features)
     image = tf.decode_raw(parsed["image"], tf.uint8)
     image = tf.image.convert_image_dtype(image, dtype=tf.float32)
     width = tf.cast(parsed["width"], tf.int32)
     height = tf.cast(parsed["height"], tf.int32)
     image = tf.reshape(image, [height, width, 1])
     image = tf.image.resize_images(image,
                                    (FLAGS.image_size, FLAGS.image_size))
     image = tf.reshape(image, [FLAGS.image_size, FLAGS.image_size, 1])
     new_image = image_preprocess.preprocess_image(image, FLAGS.image_size,
                                                   FLAGS.image_size)
     label = tf.cast(parsed["label"], tf.int32)
     return new_image, label
示例#2
0
    def parser(record):
        features = {
                'image': tf.FixedLenFeature([], tf.string, default_value=""),
                'label': tf.FixedLenFeature((), tf.int64, default_value=tf.zeros([], dtype=tf.int64)),
            }
        parsed = tf.parse_single_example(record, features)
        image = tf.decode_raw(parsed["image"], tf.uint8)

        image = tf.reshape(image, [112, 112, 1])
        image = tf.image.resize_images(image, (FLAGS.image_size, FLAGS.image_size))

        image = tf.image.convert_image_dtype(image, dtype=tf.float32)# convert to [0,1]
        image = image_preprocess.preprocess_image(image,FLAGS.image_size, FLAGS.image_size)
        label = tf.cast(parsed["label"], tf.int32)
        return image, label