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
This commit is contained in:
Pedro Cuenca 2023-10-20 13:46:06 +02:00 committed by GitHub
parent 9b1976697d
commit c030fc8913
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -226,7 +226,7 @@ class FuyuImageProcessor(BaseImageProcessor):
new_height = int(image_height * 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)
def _pad_to_target_size(self, image: np.ndarray) -> np.ndarray:

View File

@ -50,9 +50,10 @@ class TestFuyuImageProcessor(unittest.TestCase):
), f"Expected {expected_num_patches} patches, got {patches_final.shape[1]}."
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)
self.assertEqual(scaled_image.shape[0], 74)
self.assertEqual(scaled_image.shape[1], 160)
self.assertEqual(scaled_image.shape[0], 160)
self.assertEqual(scaled_image.shape[1], 74)
def test_apply_transformation_numpy(self):
transformed_image = self.processor.apply_transformation(self.sample_image)