Python vgg_preprocessing.preprocess_image() Examples
The following are 18
code examples of vgg_preprocessing.preprocess_image().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
vgg_preprocessing
, or try the search function
.
Example #1
Source File: preprocessing.py From models with Apache License 2.0 | 6 votes |
def preprocess(self, image_buffer, bbox, thread_id): """Preprocessing image_buffer using thread_id.""" # Note: Width and height of image is known only at runtime. image = tf.image.decode_jpeg(image_buffer, channels=3, dct_method='INTEGER_FAST') if self.train and self.distortions: image = distort_image(image, self.height, self.width, bbox, thread_id) else: #image = eval_image(image, self.height, self.width, bbox, thread_id, # self.resize_method) image = vgg_preprocessing.preprocess_image(image,224,224,False) # Note: image is now float32 [height,width,3] with range [0, 255] # image = tf.cast(image, tf.uint8) # HACK TESTING return image
Example #2
Source File: inception_v4.py From tpu_models with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #3
Source File: densenet_imagenet.py From class-balanced-loss with MIT License | 5 votes |
def dataset_parser(self, value): """Parse an Imagenet record from value.""" keys_to_features = { "image/encoded": tf.FixedLenFeature((), tf.string, ""), "image/format": tf.FixedLenFeature((), tf.string, "jpeg"), "image/class/label": tf.FixedLenFeature([], tf.int64, -1), "image/class/text": tf.FixedLenFeature([], tf.string, ""), "image/object/bbox/xmin": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/ymin": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/xmax": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/ymax": tf.VarLenFeature(dtype=tf.float32), "image/object/class/label": tf.VarLenFeature(dtype=tf.int64), } parsed = tf.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed["image/encoded"], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) # TODO(shivaniagrawal): height and width of image from model image = vgg_preprocessing.preprocess_image( image=image, output_height=224, output_width=224, is_training=self.is_training) label = tf.cast( tf.reshape(parsed["image/class/label"], shape=[]), dtype=tf.int32) return image, tf.one_hot(label, _LABEL_CLASSES)
Example #4
Source File: imagenet_main.py From object_detection_with_tensorflow with MIT License | 5 votes |
def record_parser(value, is_training): """Parse an ImageNet record from `value`.""" keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='jpeg'), 'image/class/label': tf.FixedLenFeature([], dtype=tf.int64, default_value=-1), 'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''), 'image/object/bbox/xmin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/xmax': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymax': tf.VarLenFeature(dtype=tf.float32), 'image/object/class/label': tf.VarLenFeature(dtype=tf.int64), } parsed = tf.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed['image/encoded'], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) image = vgg_preprocessing.preprocess_image( image=image, output_height=_DEFAULT_IMAGE_SIZE, output_width=_DEFAULT_IMAGE_SIZE, is_training=is_training) label = tf.cast( tf.reshape(parsed['image/class/label'], shape=[]), dtype=tf.int32) return image, tf.one_hot(label, _LABEL_CLASSES)
Example #5
Source File: imagenet.py From uai-sdk with Apache License 2.0 | 5 votes |
def parser(self, value, is_training): """Parse an ImageNet record from `value`.""" keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='jpeg'), 'image/class/label': tf.FixedLenFeature([], dtype=tf.int64, default_value=-1), 'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''), 'image/object/bbox/xmin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/xmax': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymax': tf.VarLenFeature(dtype=tf.float32), 'image/object/class/label': tf.VarLenFeature(dtype=tf.int64), } parsed = tf.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed['image/encoded'], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) image = vgg_preprocessing.preprocess_image( image=image, output_height=_DEFAULT_IMAGE_SIZE, output_width=_DEFAULT_IMAGE_SIZE, is_training=is_training) label = tf.cast( tf.reshape(parsed['image/class/label'], shape=[]), dtype=tf.int32) return image, label #tf.one_hot(label, _LABEL_CLASSES)
Example #6
Source File: imagenet.py From uai-sdk with Apache License 2.0 | 5 votes |
def parser(self, value, is_training): """Parse an ImageNet record from `value`.""" keys_to_features = { 'image/encoded': tf.compat.v1.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.compat.v1.FixedLenFeature((), tf.string, default_value='jpeg'), 'image/class/label': tf.compat.v1.FixedLenFeature([], dtype=tf.int64, default_value=-1), 'image/class/text': tf.compat.v1.FixedLenFeature([], dtype=tf.string, default_value=''), 'image/object/bbox/xmin': tf.compat.v1.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymin': tf.compat.v1.VarLenFeature(dtype=tf.float32), 'image/object/bbox/xmax': tf.compat.v1.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymax': tf.compat.v1.VarLenFeature(dtype=tf.float32), 'image/object/class/label': tf.compat.v1.VarLenFeature(dtype=tf.int64), } parsed = tf.compat.v1.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed['image/encoded'], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) image = vgg_preprocessing.preprocess_image( image=image, output_height=_DEFAULT_IMAGE_SIZE, output_width=_DEFAULT_IMAGE_SIZE, is_training=is_training) label = tf.cast( tf.reshape(parsed['image/class/label'], shape=[]), dtype=tf.int32) return image, label #tf.one_hot(label, _LABEL_CLASSES)
Example #7
Source File: supervised_images.py From tpu_models with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #8
Source File: densenet_keras_imagenet.py From tpu_models with Apache License 2.0 | 5 votes |
def __init__(self, is_training, data_dir, batch_size): """Constructor for ImageNetInput. Args: is_training: `bool` for whether the input is for training. data_dir: `str` for the directory of the training and validation data. batch_size: The global batch size to use. """ self.image_preprocessing_fn = vgg_preprocessing.preprocess_image self.is_training = is_training self.data_dir = data_dir self.batch_size = batch_size
Example #9
Source File: inception_v3.py From tpu_models with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #10
Source File: inception_v2.py From tpu_models with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #11
Source File: imagenet_main.py From LargeScaleIncrementalLearning with MIT License | 5 votes |
def parse_record(filename, label, is_training): """Parses a record containing a training example of an image. The input record is parsed into a label and image, and the image is passed through preprocessing steps (cropping, flipping, and so on). Args: raw_record: scalar Tensor tf.string containing a serialized Example protocol buffer. is_training: A boolean denoting whether the input is for training. Returns: Tuple with processed image tensor and one-hot-encoded label tensor. """ # Decode the string as an RGB JPEG. # Note that the resulting image contains an unknown height and width # that is set dynamically by decode_jpeg. In other words, the height # and width of image is unknown at compile-time. # Results in a 3-D int8 Tensor. This will be converted to a float later, # during resizing. print (filename) image_encoded = tf.read_file(tf.reduce_join([data_dir, '/', filename])) image_decoded = tf.image.decode_jpeg(image_encoded, channels=3) image = tf.image.decode_jpeg(image_encoded, channels=_NUM_CHANNELS) image = vgg_preprocessing.preprocess_image( image=image, output_height=_DEFAULT_IMAGE_SIZE, output_width=_DEFAULT_IMAGE_SIZE, is_training=is_training) label = tf.cast(tf.reshape(label, shape=[]), dtype=tf.int32) label = tf.one_hot(label, _NUM_CLASSES) print (image, label) return image, label
Example #12
Source File: densenet_imagenet.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def dataset_parser(self, value): """Parse an Imagenet record from value.""" keys_to_features = { "image/encoded": tf.FixedLenFeature((), tf.string, ""), "image/format": tf.FixedLenFeature((), tf.string, "jpeg"), "image/class/label": tf.FixedLenFeature([], tf.int64, -1), "image/class/text": tf.FixedLenFeature([], tf.string, ""), "image/object/bbox/xmin": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/ymin": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/xmax": tf.VarLenFeature(dtype=tf.float32), "image/object/bbox/ymax": tf.VarLenFeature(dtype=tf.float32), "image/object/class/label": tf.VarLenFeature(dtype=tf.int64), } parsed = tf.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed["image/encoded"], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) # TODO(shivaniagrawal): height and width of image from model image = vgg_preprocessing.preprocess_image( image=image, output_height=224, output_width=224, is_training=self.is_training) label = tf.cast( tf.reshape(parsed["image/class/label"], shape=[]), dtype=tf.int32) return image, tf.one_hot(label, _LABEL_CLASSES)
Example #13
Source File: mobilenet.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #14
Source File: inception_v3.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #15
Source File: inception_v2.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #16
Source File: inception_v4.py From training_results_v0.5 with Apache License 2.0 | 5 votes |
def preprocess_raw_bytes(image_bytes, is_training=False, bbox=None): """Preprocesses a raw JPEG image. This implementation is shared in common between train/eval pipelines, and when serving the model. Args: image_bytes: A string Tensor, containing the encoded JPEG. is_training: Whether or not to preprocess for training. bbox: In inception preprocessing, this bbox can be used for cropping. Returns: A 3-Tensor [height, width, RGB channels] of type float32. """ image = tf.image.decode_jpeg(image_bytes, channels=3) image = tf.image.convert_image_dtype(image, dtype=tf.float32) if FLAGS.preprocessing == 'vgg': image = vgg_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, resize_side_min=_RESIZE_SIDE_MIN, resize_side_max=_RESIZE_SIDE_MAX) elif FLAGS.preprocessing == 'inception': image = inception_preprocessing.preprocess_image( image=image, output_height=FLAGS.height, output_width=FLAGS.width, is_training=is_training, bbox=bbox) else: assert False, 'Unknown preprocessing type: %s' % FLAGS.preprocessing return image
Example #17
Source File: imagenet_main.py From yolo_v2 with Apache License 2.0 | 5 votes |
def record_parser(value, is_training): """Parse an ImageNet record from `value`.""" keys_to_features = { 'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''), 'image/format': tf.FixedLenFeature((), tf.string, default_value='jpeg'), 'image/class/label': tf.FixedLenFeature([], dtype=tf.int64, default_value=-1), 'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''), 'image/object/bbox/xmin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymin': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/xmax': tf.VarLenFeature(dtype=tf.float32), 'image/object/bbox/ymax': tf.VarLenFeature(dtype=tf.float32), 'image/object/class/label': tf.VarLenFeature(dtype=tf.int64), } parsed = tf.parse_single_example(value, keys_to_features) image = tf.image.decode_image( tf.reshape(parsed['image/encoded'], shape=[]), _NUM_CHANNELS) image = tf.image.convert_image_dtype(image, dtype=tf.float32) image = vgg_preprocessing.preprocess_image( image=image, output_height=_DEFAULT_IMAGE_SIZE, output_width=_DEFAULT_IMAGE_SIZE, is_training=is_training) label = tf.cast( tf.reshape(parsed['image/class/label'], shape=[]), dtype=tf.int32) return image, tf.one_hot(label, _LABEL_CLASSES)
Example #18
Source File: preprocessing.py From models with Apache License 2.0 | 5 votes |
def parse_and_preprocess(self, value): # parse image_buffer, label_index = parse_example_proto(value) # preprocess image = tf.image.decode_jpeg( image_buffer, channels=3, fancy_upscaling=False, dct_method='INTEGER_FAST') image = vgg_preprocessing.preprocess_image(image,224,224,False) return (image, label_index)