Unverified Commit c86f7916 authored by pkulzc's avatar pkulzc Committed by GitHub
Browse files

Merge pull request #2146 to fix data augmentation functions.

Removing unnecessary clipping in preprocessor.py (fix #2066)
parents 31f7f41b e627d395
...@@ -736,7 +736,7 @@ def random_pixel_value_scale(image, ...@@ -736,7 +736,7 @@ def random_pixel_value_scale(image,
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
minval: lower ratio of scaling pixel values. minval: lower ratio of scaling pixel values.
maxval: upper ratio of scaling pixel values. maxval: upper ratio of scaling pixel values.
seed: random seed. seed: random seed.
...@@ -759,7 +759,7 @@ def random_pixel_value_scale(image, ...@@ -759,7 +759,7 @@ def random_pixel_value_scale(image,
preprocess_vars_cache) preprocess_vars_cache)
image = tf.multiply(image, color_coef) image = tf.multiply(image, color_coef)
image = tf.clip_by_value(image, 0.0, 1.0) image = tf.clip_by_value(image, 0.0, 255.0)
return image return image
...@@ -825,7 +825,7 @@ def random_rgb_to_gray(image, ...@@ -825,7 +825,7 @@ def random_rgb_to_gray(image,
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
probability: the probability of returning a grayscale image. probability: the probability of returning a grayscale image.
The probability should be a number between [0, 1]. The probability should be a number between [0, 1].
seed: random seed. seed: random seed.
...@@ -862,11 +862,11 @@ def random_adjust_brightness(image, ...@@ -862,11 +862,11 @@ def random_adjust_brightness(image,
preprocess_vars_cache=None): preprocess_vars_cache=None):
"""Randomly adjusts brightness. """Randomly adjusts brightness.
Makes sure the output image is still between 0 and 1. Makes sure the output image is still between 0 and 255.
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
max_delta: how much to change the brightness. A value between [0, 1). max_delta: how much to change the brightness. A value between [0, 1).
seed: random seed. seed: random seed.
preprocess_vars_cache: PreprocessorCache object that records previously preprocess_vars_cache: PreprocessorCache object that records previously
...@@ -886,8 +886,8 @@ def random_adjust_brightness(image, ...@@ -886,8 +886,8 @@ def random_adjust_brightness(image,
preprocessor_cache.PreprocessorCache.ADJUST_BRIGHTNESS, preprocessor_cache.PreprocessorCache.ADJUST_BRIGHTNESS,
preprocess_vars_cache) preprocess_vars_cache)
image = tf.image.adjust_brightness(image, delta) image = tf.image.adjust_brightness(image / 255, delta) * 255
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0) image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
return image return image
...@@ -898,11 +898,11 @@ def random_adjust_contrast(image, ...@@ -898,11 +898,11 @@ def random_adjust_contrast(image,
preprocess_vars_cache=None): preprocess_vars_cache=None):
"""Randomly adjusts contrast. """Randomly adjusts contrast.
Makes sure the output image is still between 0 and 1. Makes sure the output image is still between 0 and 255.
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
min_delta: see max_delta. min_delta: see max_delta.
max_delta: how much to change the contrast. Contrast will change with a max_delta: how much to change the contrast. Contrast will change with a
value between min_delta and max_delta. This value will be value between min_delta and max_delta. This value will be
...@@ -923,8 +923,8 @@ def random_adjust_contrast(image, ...@@ -923,8 +923,8 @@ def random_adjust_contrast(image,
generator_func, generator_func,
preprocessor_cache.PreprocessorCache.ADJUST_CONTRAST, preprocessor_cache.PreprocessorCache.ADJUST_CONTRAST,
preprocess_vars_cache) preprocess_vars_cache)
image = tf.image.adjust_contrast(image, contrast_factor) image = tf.image.adjust_contrast(image / 255, contrast_factor) * 255
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0) image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
return image return image
...@@ -934,11 +934,11 @@ def random_adjust_hue(image, ...@@ -934,11 +934,11 @@ def random_adjust_hue(image,
preprocess_vars_cache=None): preprocess_vars_cache=None):
"""Randomly adjusts hue. """Randomly adjusts hue.
Makes sure the output image is still between 0 and 1. Makes sure the output image is still between 0 and 255.
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
max_delta: change hue randomly with a value between 0 and max_delta. max_delta: change hue randomly with a value between 0 and max_delta.
seed: random seed. seed: random seed.
preprocess_vars_cache: PreprocessorCache object that records previously preprocess_vars_cache: PreprocessorCache object that records previously
...@@ -955,8 +955,8 @@ def random_adjust_hue(image, ...@@ -955,8 +955,8 @@ def random_adjust_hue(image,
delta = _get_or_create_preprocess_rand_vars( delta = _get_or_create_preprocess_rand_vars(
generator_func, preprocessor_cache.PreprocessorCache.ADJUST_HUE, generator_func, preprocessor_cache.PreprocessorCache.ADJUST_HUE,
preprocess_vars_cache) preprocess_vars_cache)
image = tf.image.adjust_hue(image, delta) image = tf.image.adjust_hue(image / 255, delta) * 255
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0) image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
return image return image
...@@ -967,11 +967,11 @@ def random_adjust_saturation(image, ...@@ -967,11 +967,11 @@ def random_adjust_saturation(image,
preprocess_vars_cache=None): preprocess_vars_cache=None):
"""Randomly adjusts saturation. """Randomly adjusts saturation.
Makes sure the output image is still between 0 and 1. Makes sure the output image is still between 0 and 255.
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
min_delta: see max_delta. min_delta: see max_delta.
max_delta: how much to change the saturation. Saturation will change with a max_delta: how much to change the saturation. Saturation will change with a
value between min_delta and max_delta. This value will be value between min_delta and max_delta. This value will be
...@@ -992,8 +992,8 @@ def random_adjust_saturation(image, ...@@ -992,8 +992,8 @@ def random_adjust_saturation(image,
generator_func, generator_func,
preprocessor_cache.PreprocessorCache.ADJUST_SATURATION, preprocessor_cache.PreprocessorCache.ADJUST_SATURATION,
preprocess_vars_cache) preprocess_vars_cache)
image = tf.image.adjust_saturation(image, saturation_factor) image = tf.image.adjust_saturation(image / 255, saturation_factor) * 255
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0) image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
return image return image
...@@ -1001,11 +1001,11 @@ def random_distort_color(image, color_ordering=0, preprocess_vars_cache=None): ...@@ -1001,11 +1001,11 @@ def random_distort_color(image, color_ordering=0, preprocess_vars_cache=None):
"""Randomly distorts color. """Randomly distorts color.
Randomly distorts color using a combination of brightness, hue, contrast Randomly distorts color using a combination of brightness, hue, contrast
and saturation changes. Makes sure the output image is still between 0 and 1. and saturation changes. Makes sure the output image is still between 0 and 255.
Args: Args:
image: rank 3 float32 tensor contains 1 image -> [height, width, channels] image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
with pixel values varying between [0, 1]. with pixel values varying between [0, 255].
color_ordering: Python int, a type of distortion (valid values: 0, 1). color_ordering: Python int, a type of distortion (valid values: 0, 1).
preprocess_vars_cache: PreprocessorCache object that records previously preprocess_vars_cache: PreprocessorCache object that records previously
performed augmentations. Updated in-place. If this performed augmentations. Updated in-place. If this
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment