Unverified Commit c030fc89 authored by Pedro Cuenca's avatar Pedro Cuenca Committed by GitHub
Browse files

Fix Fuyu image scaling bug (#26918)

* Fix Fuyu image scaling bug

It could produce negative padding and hence inference errors for certain
image sizes.

* Fix aspect ratio scaling test
parent 9b197669
...@@ -226,7 +226,7 @@ class FuyuImageProcessor(BaseImageProcessor): ...@@ -226,7 +226,7 @@ class FuyuImageProcessor(BaseImageProcessor):
new_height = int(image_height * optimal_scale_factor) new_height = int(image_height * optimal_scale_factor)
new_width = int(image_width * optimal_scale_factor) new_width = int(image_width * optimal_scale_factor)
scaled_image = resize(image=image, size=(new_width, new_height)) scaled_image = resize(image=image, size=(new_height, new_width))
return np.array(scaled_image) return np.array(scaled_image)
def _pad_to_target_size(self, image: np.ndarray) -> np.ndarray: def _pad_to_target_size(self, image: np.ndarray) -> np.ndarray:
......
...@@ -50,9 +50,10 @@ class TestFuyuImageProcessor(unittest.TestCase): ...@@ -50,9 +50,10 @@ class TestFuyuImageProcessor(unittest.TestCase):
), f"Expected {expected_num_patches} patches, got {patches_final.shape[1]}." ), f"Expected {expected_num_patches} patches, got {patches_final.shape[1]}."
def test_scale_to_target_aspect_ratio(self): def test_scale_to_target_aspect_ratio(self):
# (h:450, w:210) fitting (160, 320) -> (160, 210*160/450)
scaled_image = self.processor._scale_to_target_aspect_ratio(self.sample_image) scaled_image = self.processor._scale_to_target_aspect_ratio(self.sample_image)
self.assertEqual(scaled_image.shape[0], 74) self.assertEqual(scaled_image.shape[0], 160)
self.assertEqual(scaled_image.shape[1], 160) self.assertEqual(scaled_image.shape[1], 74)
def test_apply_transformation_numpy(self): def test_apply_transformation_numpy(self):
transformed_image = self.processor.apply_transformation(self.sample_image) transformed_image = self.processor.apply_transformation(self.sample_image)
......
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