mirror of
https://github.com/huggingface/transformers.git
synced 2025-08-03 03:31:05 +06:00
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:
parent
9b1976697d
commit
c030fc8913
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user