Skip to content

Commit

Permalink
Implement check to skip value range transform (keras-team#198)
Browse files Browse the repository at this point in the history
* Implement check to skip value range transform

* add simple test case

* Run format
  • Loading branch information
(Ian Stenbit) committed Mar 23, 2022
1 parent de231a9 commit e13b325
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions keras_cv/utils/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def transform_value_range(images, original_range, target_range, dtype=tf.float32
)
```
"""
if original_range[0] == target_range[0] and original_range[1] == target_range[1]:
return images

images = tf.cast(images, dtype=dtype)
original_min_value, original_max_value = _unwrap_value_range(
original_range, dtype=dtype
Expand Down
7 changes: 7 additions & 0 deletions keras_cv/utils/preprocessing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ def test_transform_to_standard_range_neg_one_range(self):
)
self.assertAllClose(x, [0.0, 127.5, 255.0])

def test_transform_to_same_range(self):
x = tf.constant([-1, 0, 1])
x = preprocessing.transform_value_range(
x, original_range=[0, 255], target_range=[0, 255]
)
self.assertAllClose(x, [-1, 0, 1])

def test_transform_to_standard_range(self):
x = tf.constant([8 / 255, 9 / 255, 255 / 255])
x = preprocessing.transform_value_range(
Expand Down

0 comments on commit e13b325

Please sign in to comment.