Skip to content

Commit c86f791

Browse files
authored
Merge pull request tensorflow#2146 to fix data augmentation functions.
Removing unnecessary clipping in preprocessor.py (fix tensorflow#2066)
2 parents 31f7f41 + e627d39 commit c86f791

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

research/object_detection/core/preprocessor.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ def random_pixel_value_scale(image,
736736
737737
Args:
738738
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
739-
with pixel values varying between [0, 1].
739+
with pixel values varying between [0, 255].
740740
minval: lower ratio of scaling pixel values.
741741
maxval: upper ratio of scaling pixel values.
742742
seed: random seed.
@@ -759,7 +759,7 @@ def random_pixel_value_scale(image,
759759
preprocess_vars_cache)
760760

761761
image = tf.multiply(image, color_coef)
762-
image = tf.clip_by_value(image, 0.0, 1.0)
762+
image = tf.clip_by_value(image, 0.0, 255.0)
763763

764764
return image
765765

@@ -825,7 +825,7 @@ def random_rgb_to_gray(image,
825825
826826
Args:
827827
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
828-
with pixel values varying between [0, 1].
828+
with pixel values varying between [0, 255].
829829
probability: the probability of returning a grayscale image.
830830
The probability should be a number between [0, 1].
831831
seed: random seed.
@@ -862,11 +862,11 @@ def random_adjust_brightness(image,
862862
preprocess_vars_cache=None):
863863
"""Randomly adjusts brightness.
864864
865-
Makes sure the output image is still between 0 and 1.
865+
Makes sure the output image is still between 0 and 255.
866866
867867
Args:
868868
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
869-
with pixel values varying between [0, 1].
869+
with pixel values varying between [0, 255].
870870
max_delta: how much to change the brightness. A value between [0, 1).
871871
seed: random seed.
872872
preprocess_vars_cache: PreprocessorCache object that records previously
@@ -886,8 +886,8 @@ def random_adjust_brightness(image,
886886
preprocessor_cache.PreprocessorCache.ADJUST_BRIGHTNESS,
887887
preprocess_vars_cache)
888888

889-
image = tf.image.adjust_brightness(image, delta)
890-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
889+
image = tf.image.adjust_brightness(image / 255, delta) * 255
890+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
891891
return image
892892

893893

@@ -898,11 +898,11 @@ def random_adjust_contrast(image,
898898
preprocess_vars_cache=None):
899899
"""Randomly adjusts contrast.
900900
901-
Makes sure the output image is still between 0 and 1.
901+
Makes sure the output image is still between 0 and 255.
902902
903903
Args:
904904
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
905-
with pixel values varying between [0, 1].
905+
with pixel values varying between [0, 255].
906906
min_delta: see max_delta.
907907
max_delta: how much to change the contrast. Contrast will change with a
908908
value between min_delta and max_delta. This value will be
@@ -923,8 +923,8 @@ def random_adjust_contrast(image,
923923
generator_func,
924924
preprocessor_cache.PreprocessorCache.ADJUST_CONTRAST,
925925
preprocess_vars_cache)
926-
image = tf.image.adjust_contrast(image, contrast_factor)
927-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
926+
image = tf.image.adjust_contrast(image / 255, contrast_factor) * 255
927+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
928928
return image
929929

930930

@@ -934,11 +934,11 @@ def random_adjust_hue(image,
934934
preprocess_vars_cache=None):
935935
"""Randomly adjusts hue.
936936
937-
Makes sure the output image is still between 0 and 1.
937+
Makes sure the output image is still between 0 and 255.
938938
939939
Args:
940940
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
941-
with pixel values varying between [0, 1].
941+
with pixel values varying between [0, 255].
942942
max_delta: change hue randomly with a value between 0 and max_delta.
943943
seed: random seed.
944944
preprocess_vars_cache: PreprocessorCache object that records previously
@@ -955,8 +955,8 @@ def random_adjust_hue(image,
955955
delta = _get_or_create_preprocess_rand_vars(
956956
generator_func, preprocessor_cache.PreprocessorCache.ADJUST_HUE,
957957
preprocess_vars_cache)
958-
image = tf.image.adjust_hue(image, delta)
959-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
958+
image = tf.image.adjust_hue(image / 255, delta) * 255
959+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
960960
return image
961961

962962

@@ -967,11 +967,11 @@ def random_adjust_saturation(image,
967967
preprocess_vars_cache=None):
968968
"""Randomly adjusts saturation.
969969
970-
Makes sure the output image is still between 0 and 1.
970+
Makes sure the output image is still between 0 and 255.
971971
972972
Args:
973973
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
974-
with pixel values varying between [0, 1].
974+
with pixel values varying between [0, 255].
975975
min_delta: see max_delta.
976976
max_delta: how much to change the saturation. Saturation will change with a
977977
value between min_delta and max_delta. This value will be
@@ -992,20 +992,20 @@ def random_adjust_saturation(image,
992992
generator_func,
993993
preprocessor_cache.PreprocessorCache.ADJUST_SATURATION,
994994
preprocess_vars_cache)
995-
image = tf.image.adjust_saturation(image, saturation_factor)
996-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
995+
image = tf.image.adjust_saturation(image / 255, saturation_factor) * 255
996+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
997997
return image
998998

999999

10001000
def random_distort_color(image, color_ordering=0, preprocess_vars_cache=None):
10011001
"""Randomly distorts color.
10021002
10031003
Randomly distorts color using a combination of brightness, hue, contrast
1004-
and saturation changes. Makes sure the output image is still between 0 and 1.
1004+
and saturation changes. Makes sure the output image is still between 0 and 255.
10051005
10061006
Args:
10071007
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
1008-
with pixel values varying between [0, 1].
1008+
with pixel values varying between [0, 255].
10091009
color_ordering: Python int, a type of distortion (valid values: 0, 1).
10101010
preprocess_vars_cache: PreprocessorCache object that records previously
10111011
performed augmentations. Updated in-place. If this

0 commit comments

Comments
 (0)