本文整理匯總了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