Skip to content

Commit e627d39

Browse files
committed
Removing unecessary clipping in preprocessor.py (fix tensorflow#2066)
1 parent 20a4313 commit e627d39

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

research/object_detection/core/preprocessor.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def random_pixel_value_scale(image,
726726
727727
Args:
728728
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
729-
with pixel values varying between [0, 1].
729+
with pixel values varying between [0, 255].
730730
minval: lower ratio of scaling pixel values.
731731
maxval: upper ratio of scaling pixel values.
732732
seed: random seed.
@@ -749,7 +749,7 @@ def random_pixel_value_scale(image,
749749
preprocess_vars_cache)
750750

751751
image = tf.multiply(image, color_coef)
752-
image = tf.clip_by_value(image, 0.0, 1.0)
752+
image = tf.clip_by_value(image, 0.0, 255.0)
753753

754754
return image
755755

@@ -815,7 +815,7 @@ def random_rgb_to_gray(image,
815815
816816
Args:
817817
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
818-
with pixel values varying between [0, 1].
818+
with pixel values varying between [0, 255].
819819
probability: the probability of returning a grayscale image.
820820
The probability should be a number between [0, 1].
821821
seed: random seed.
@@ -852,11 +852,11 @@ def random_adjust_brightness(image,
852852
preprocess_vars_cache=None):
853853
"""Randomly adjusts brightness.
854854
855-
Makes sure the output image is still between 0 and 1.
855+
Makes sure the output image is still between 0 and 255.
856856
857857
Args:
858858
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
859-
with pixel values varying between [0, 1].
859+
with pixel values varying between [0, 255].
860860
max_delta: how much to change the brightness. A value between [0, 1).
861861
seed: random seed.
862862
preprocess_vars_cache: PreprocessorCache object that records previously
@@ -876,8 +876,8 @@ def random_adjust_brightness(image,
876876
preprocessor_cache.PreprocessorCache.ADJUST_BRIGHTNESS,
877877
preprocess_vars_cache)
878878

879-
image = tf.image.adjust_brightness(image, delta)
880-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
879+
image = tf.image.adjust_brightness(image / 255, delta) * 255
880+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
881881
return image
882882

883883

@@ -888,11 +888,11 @@ def random_adjust_contrast(image,
888888
preprocess_vars_cache=None):
889889
"""Randomly adjusts contrast.
890890
891-
Makes sure the output image is still between 0 and 1.
891+
Makes sure the output image is still between 0 and 255.
892892
893893
Args:
894894
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
895-
with pixel values varying between [0, 1].
895+
with pixel values varying between [0, 255].
896896
min_delta: see max_delta.
897897
max_delta: how much to change the contrast. Contrast will change with a
898898
value between min_delta and max_delta. This value will be
@@ -913,8 +913,8 @@ def random_adjust_contrast(image,
913913
generator_func,
914914
preprocessor_cache.PreprocessorCache.ADJUST_CONTRAST,
915915
preprocess_vars_cache)
916-
image = tf.image.adjust_contrast(image, contrast_factor)
917-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
916+
image = tf.image.adjust_contrast(image / 255, contrast_factor) * 255
917+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
918918
return image
919919

920920

@@ -924,11 +924,11 @@ def random_adjust_hue(image,
924924
preprocess_vars_cache=None):
925925
"""Randomly adjusts hue.
926926
927-
Makes sure the output image is still between 0 and 1.
927+
Makes sure the output image is still between 0 and 255.
928928
929929
Args:
930930
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
931-
with pixel values varying between [0, 1].
931+
with pixel values varying between [0, 255].
932932
max_delta: change hue randomly with a value between 0 and max_delta.
933933
seed: random seed.
934934
preprocess_vars_cache: PreprocessorCache object that records previously
@@ -945,8 +945,8 @@ def random_adjust_hue(image,
945945
delta = _get_or_create_preprocess_rand_vars(
946946
generator_func, preprocessor_cache.PreprocessorCache.ADJUST_HUE,
947947
preprocess_vars_cache)
948-
image = tf.image.adjust_hue(image, delta)
949-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
948+
image = tf.image.adjust_hue(image / 255, delta) * 255
949+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
950950
return image
951951

952952

@@ -957,11 +957,11 @@ def random_adjust_saturation(image,
957957
preprocess_vars_cache=None):
958958
"""Randomly adjusts saturation.
959959
960-
Makes sure the output image is still between 0 and 1.
960+
Makes sure the output image is still between 0 and 255.
961961
962962
Args:
963963
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
964-
with pixel values varying between [0, 1].
964+
with pixel values varying between [0, 255].
965965
min_delta: see max_delta.
966966
max_delta: how much to change the saturation. Saturation will change with a
967967
value between min_delta and max_delta. This value will be
@@ -982,20 +982,20 @@ def random_adjust_saturation(image,
982982
generator_func,
983983
preprocessor_cache.PreprocessorCache.ADJUST_SATURATION,
984984
preprocess_vars_cache)
985-
image = tf.image.adjust_saturation(image, saturation_factor)
986-
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0)
985+
image = tf.image.adjust_saturation(image / 255, saturation_factor) * 255
986+
image = tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=255.0)
987987
return image
988988

989989

990990
def random_distort_color(image, color_ordering=0, preprocess_vars_cache=None):
991991
"""Randomly distorts color.
992992
993993
Randomly distorts color using a combination of brightness, hue, contrast
994-
and saturation changes. Makes sure the output image is still between 0 and 1.
994+
and saturation changes. Makes sure the output image is still between 0 and 255.
995995
996996
Args:
997997
image: rank 3 float32 tensor contains 1 image -> [height, width, channels]
998-
with pixel values varying between [0, 1].
998+
with pixel values varying between [0, 255].
999999
color_ordering: Python int, a type of distortion (valid values: 0, 1).
10001000
preprocess_vars_cache: PreprocessorCache object that records previously
10011001
performed augmentations. Updated in-place. If this

0 commit comments

Comments
 (0)