本文整理汇总了Python中inception_preprocessing.preprocess_image方法的典型用法代码示例。如果您正苦于以下问题:Python inception_preprocessing.preprocess_image方法的具体用法?Python inception_preprocessing.preprocess_image怎么用?Python inception_preprocessing.preprocess_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inception_preprocessing
的用法示例。
在下文中一共展示了inception_preprocessing.preprocess_image方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_inception_preprocess_patches
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def get_inception_preprocess_patches(is_training, resize_size, num_patches):
def _inception_preprocess_patches(data):
patches = []
for _ in range(num_patches):
patches.append(
inception_pp.preprocess_image(
data["image"],
resize_size[0],
resize_size[1],
is_training,
add_image_summaries=False))
patches = tf.stack(patches)
data["image"] = patches
return data
return _inception_preprocess_patches
示例2: get_inception_preprocess_patches
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def get_inception_preprocess_patches(is_training, resize_size, num_of_patches):
def _inception_preprocess_patches(data):
patches = []
for _ in range(num_of_patches):
patches.append(
inception_preprocessing.preprocess_image(
data["image"],
resize_size[0],
resize_size[1],
is_training,
add_image_summaries=False))
patches = tf.stack(patches)
data["image"] = patches
return data
return _inception_preprocess_patches
示例3: preprocess_raw_bytes
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_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
示例4: get_inception_preprocess
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def get_inception_preprocess(is_training, im_size):
def _inception_preprocess(data):
data["image"] = inception_pp.preprocess_image(
data["image"], im_size[0], im_size[1], is_training,
add_image_summaries=False)
return data
return _inception_preprocess
示例5: get_inception_preprocess
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def get_inception_preprocess(is_training, im_size):
def _inception_preprocess(data):
data["image"] = inception_preprocessing.preprocess_image(
data["image"], im_size[0], im_size[1], is_training,
add_image_summaries=False)
return data
return _inception_preprocess
示例6: _dataset_parser
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def _dataset_parser(self, serialized_proto):
"""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),
}
features = tf.parse_single_example(serialized_proto, keys_to_features)
bbox = None
image = features['image/encoded']
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
image = inception_preprocessing.preprocess_image(
image=image,
output_height=self.hparams.image_size,
output_width=self.hparams.image_size,
is_training=self.is_training,
# If eval_from_hub, do not scale the images during preprocessing.
scaled_images=not self.eval_from_hub,
bbox=bbox)
label = tf.cast(
tf.reshape(features['image/class/label'], shape=[]), dtype=tf.int32)
return image, label
示例7: _rgb_preprocessing
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def _rgb_preprocessing(
self, rgb_image_op,
image_augmentation=None,
imagenet_preprocessing=None,
resize=None,
resize_height=None,
resize_width=None,
mode='tf'):
"""Preprocess an rgb image into a float image, applying image augmentation and imagenet mean subtraction if desired.
Please note that cropped images are generated in `_image_decode()` and given separate feature names.
Also please be very careful about resizing the rgb image
# Arguments
mode: One of "caffe", "tf" or "torch".
- caffe: will convert the images from RGB to BGR,
then will zero-center each color channel with
respect to the ImageNet dataset,
without scaling.
- tf: will scale pixels between -1 and 1,
sample-wise.
- torch: will scale pixels between 0 and 1 and then
will normalize each channel with respect to the
ImageNet dataset.
"""
with tf.name_scope('rgb_preprocessing'):
if image_augmentation is None:
image_augmentation = FLAGS.image_augmentation
if imagenet_preprocessing is None:
imagenet_preprocessing = FLAGS.imagenet_preprocessing
if resize is None:
resize = FLAGS.resize
if resize_height is None:
resize_height = FLAGS.resize_height
if resize_width is None:
resize_width = FLAGS.resize_width
# make sure the shape is correct
rgb_image_op = tf.squeeze(rgb_image_op)
# apply image augmentation and imagenet preprocessing steps adapted from keras
if resize:
rgb_image_op = tf.image.resize_images(rgb_image_op,
tf.constant([resize_height, resize_width],
name='resize_height_width'))
if imagenet_preprocessing:
data_format = K.image_data_format()
# TODO(ahundt) add scaling to augmentation and use that to augment delta depth parameters
# TODO(ahundt) possibly subtract imagenet mean if using pretrained weights, also simply divide channels by 255, and see https://github.com/tensorflow/tensorflow/issues/15722
rgb_image_op = inception_preprocessing.preprocess_image(
rgb_image_op,
is_training=image_augmentation,
fast_mode=False,
mode=mode, data_format=data_format)
else:
rgb_image_op = tf.cast(rgb_image_op, tf.float32)
return rgb_image_op
示例8: _dataset_parser
# 需要导入模块: import inception_preprocessing [as 别名]
# 或者: from inception_preprocessing import preprocess_image [as 别名]
def _dataset_parser(self, serialized_proto):
"""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),
}
features = tf.parse_single_example(serialized_proto, keys_to_features)
bbox = None
image = features['image/encoded']
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, dtype=tf.float32)
image = inception_preprocessing.preprocess_image(
image=image,
output_height=self.hparams.image_size,
output_width=self.hparams.image_size,
is_training=self.is_training,
bbox=bbox)
label = tf.cast(
tf.reshape(features['image/class/label'], shape=[]), dtype=tf.int32)
return image, label