本文整理汇总了Python中preprocessing.inception_preprocessing.apply_with_random_selector方法的典型用法代码示例。如果您正苦于以下问题:Python inception_preprocessing.apply_with_random_selector方法的具体用法?Python inception_preprocessing.apply_with_random_selector怎么用?Python inception_preprocessing.apply_with_random_selector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类preprocessing.inception_preprocessing
的用法示例。
在下文中一共展示了inception_preprocessing.apply_with_random_selector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: distort_image
# 需要导入模块: from preprocessing import inception_preprocessing [as 别名]
# 或者: from preprocessing.inception_preprocessing import apply_with_random_selector [as 别名]
def distort_image(im, fast_mode=False):
# All images in the same batch are transformed the same way, but over
# iterations you see different distortions.
# im should be float with values between 0 and 1.
im_ = tf.reshape(im, shape=(-1,1,3))
im_ = ip.apply_with_random_selector(
im_, lambda x, ordering: ip.distort_color(x, ordering, fast_mode),
num_cases=4)
im_ = tf.reshape(im_, tf.shape(im))
return im_
示例2: distort_randomly_image_color
# 需要导入模块: from preprocessing import inception_preprocessing [as 别名]
# 或者: from preprocessing.inception_preprocessing import apply_with_random_selector [as 别名]
def distort_randomly_image_color(image_tensor, fast_mode=False):
"""Accepts image tensor of (width, height, 3) and returns color distorted image.
The function performs random brightness, saturation, hue, contrast change as it is performed
for inception model training in TF-Slim (you can find the link below in comments). All the
parameters of random variables were originally preserved. There are two regimes for the function
to work: fast and slow. Slow one performs only saturation and brightness random change is performed.
Parameters
----------
image_tensor : Tensor of size (width, height, 3) of tf.int32 or tf.float
Tensor with image with range [0,255]
fast_mode : boolean
Boolean value representing whether to use fast or slow mode
Returns
-------
img_float_distorted_original_range : Tensor of size (width, height, 3) of type tf.float.
Image Tensor with distorted color in [0,255] intensity range
"""
# Make the range to be in [0,1]
img_float_zero_one_range = tf.to_float(image_tensor) / 255
# Randomly distort the color of image. There are 4 ways to do it.
# Credit: TF-Slim
# https://github.com/tensorflow/models/blob/master/slim/preprocessing/inception_preprocessing.py#L224
# Most probably the inception models were trainined using this color augmentation:
# https://github.com/tensorflow/models/tree/master/slim#pre-trained-models
distorted_image = apply_with_random_selector(img_float_zero_one_range,
lambda x, ordering: distort_color(x, ordering, fast_mode=fast_mode),
num_cases=4)
img_float_distorted_original_range = distorted_image * 255
return img_float_distorted_original_range