def parse(record, is_training): features = { 'image/encoded': tf.io.FixedLenFeature((), tf.string), 'image/class/label': tf.io.FixedLenFeature((), tf.int64), 'image/object/bbox/xmin': tf.io.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymin': tf.io.VarLenFeature(dtype=tf.float32), 'image/object/bbox/xmax': tf.io.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymax': tf.io.VarLenFeature(dtype=tf.float32), } parsed = tf.io.parse_single_example(record, features) image_bytes = tf.reshape(parsed['image/encoded'], shape=[]) # bbox = tf.constant([0.0, 0.0, 1.0, 1.0], dtype=tf.float32, shape=[1, 1, 4]) bbox = tf.stack([ parsed['image/object/bbox/%s' % x].values for x in ['ymin', 'xmin', 'ymax', 'xmax'] ]) bbox = tf.transpose(tf.expand_dims(bbox, 0), [0, 2, 1]) image = resnet_preprocessing.preprocess_image(image_bytes, bbox, 224, 224, 3, is_training=is_training) label = tf.cast(parsed['image/class/label'] - 1, tf.int32) one_hot_label = tf.one_hot(label, depth=1000, dtype=tf.int32) return image, one_hot_label
def _preprocess_image(image_bytes): """Preprocess a single raw image.""" image = tf.image.decode_image(tf.reshape(image_bytes, shape=[]), 3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) image = resnet_preprocessing.preprocess_image(image=image, is_training=False) return image
def _preprocess_image(image_bytes): """Preprocess a single raw image.""" image = resnet_preprocessing.preprocess_image(image_bytes=image_bytes, is_training=False) return image