本文整理汇总了Python中vgg_preprocessing.preprocess_image方法的典型用法代码示例。如果您正苦于以下问题:Python vgg_preprocessing.preprocess_image方法的具体用法?Python vgg_preprocessing.preprocess_image怎么用?Python vgg_preprocessing.preprocess_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vgg_preprocessing
的用法示例。
在下文中一共展示了vgg_preprocessing.preprocess_image方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocess
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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
示例2: parse_record
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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
示例3: parse_and_preprocess
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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)
示例4: record_parser
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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)
示例5: preprocess_raw_bytes
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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
示例6: dataset_parser
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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)
示例7: __init__
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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
示例8: parser
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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)
示例9: parser
# 需要导入模块: import vgg_preprocessing [as 别名]
# 或者: from vgg_preprocessing import preprocess_image [as 别名]
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)