Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 689038687
  • Loading branch information
tensorflower-gardener committed Oct 23, 2024
1 parent 7ffafd0 commit 12c77c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions official/vision/ops/preprocess_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def resize_and_crop_image(
2. Pad the rescaled image to the padded_size.
Args:
image: a `Tensor` of shape [height, width, 3] representing an image.
image: a `Tensor` of shape [height, width, c] representing an image.
desired_size: a `Tensor` or `int` list/tuple of two elements representing
[height, width] of the desired actual output image size.
padded_size: a `Tensor` or `int` list/tuple of two elements representing
Expand All @@ -201,7 +201,7 @@ def resize_and_crop_image(
behaviour is to place it at left top corner.
Returns:
output_image: `Tensor` of shape [height, width, 3] where [height, width]
output_image: `Tensor` of shape [height, width, c] where [height, width]
equals to `output_size`.
image_info: a 2D `Tensor` that encodes the information of the image and the
applied preprocessing. It is in the format of
Expand Down Expand Up @@ -786,7 +786,7 @@ def random_horizontal_flip(
"""Randomly flips input image and bounding boxes and/or masks horizontally.
Expects input tensors without the batch dimension; i.e. for RGB image assume
rank-3 input like [h, w, 3], for masks assume either [h, w, 1] or [1, h, w].
rank-3 input like [h, w, c], for masks assume either [h, w, 1] or [1, h, w].
Args:
image: `tf.Tensor`, the image to apply the random flip, [h, w, channels].
Expand Down
16 changes: 12 additions & 4 deletions official/vision/ops/preprocess_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,19 @@ def test_pad_to_fixed_size(
aug_scale_max=2.0,
output_scales=(20 / 100, 10 / 200),
),
dict(
testcase_name='no_jittering_with_4_channels',
input_size=(100, 200),
desired_size=(20, 10),
aug_scale_max=1.0,
output_scales=(20 / 100, 10 / 200),
channels=4,
),
)
def test_resize_and_crop_image_not_keep_aspect_ratio(
self, input_size, desired_size, aug_scale_max, output_scales
self, input_size, desired_size, aug_scale_max, output_scales, channels=3
):
image = tf.convert_to_tensor(np.random.rand(*input_size, 3))
image = tf.convert_to_tensor(np.random.rand(*input_size, channels))

resized_image, image_info = preprocess_ops.resize_and_crop_image(
image,
Expand All @@ -95,7 +103,7 @@ def test_resize_and_crop_image_not_keep_aspect_ratio(
)
resized_image_shape = tf.shape(resized_image)

self.assertAllEqual([*desired_size, 3], resized_image_shape.numpy())
self.assertAllEqual([*desired_size, channels], resized_image_shape.numpy())
if aug_scale_max == 1:
self.assertNDArrayNear(
[input_size, desired_size, output_scales, [0.0, 0.0]],
Expand All @@ -108,7 +116,7 @@ def test_resize_and_crop_image_not_keep_aspect_ratio(
(100, 256, 128, 256, 32, 1.0, 1.0, 128, 256),
(200, 512, 200, 128, 32, 0.25, 0.25, 224, 128),
)
def test_resize_and_crop_image_rectangluar_case(
def test_resize_and_crop_image_rectangular_case(
self,
input_height,
input_width,
Expand Down

0 comments on commit 12c77c9

Please sign in to comment.