From 7426d02ea8396aef6206fdbcdd7ae92f96a468b4 Mon Sep 17 00:00:00 2001 From: Zebin Date: Tue, 18 Mar 2025 16:05:06 +0530 Subject: [PATCH] Fixing typo in gemma3 image_processor_fast and adding a small test (#36776) Co-authored-by: zebz13 Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com> --- .../gemma3/image_processing_gemma3_fast.py | 6 ++--- .../gemma3/test_image_processing_gemma3.py | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/transformers/models/gemma3/image_processing_gemma3_fast.py b/src/transformers/models/gemma3/image_processing_gemma3_fast.py index 6af4985dfd..47a676ce2a 100644 --- a/src/transformers/models/gemma3/image_processing_gemma3_fast.py +++ b/src/transformers/models/gemma3/image_processing_gemma3_fast.py @@ -277,17 +277,17 @@ class Gemma3ImageProcessorFast(BaseImageProcessorFast): processed_images = [] batch_num_crops = [] - for image_list in images: + for images_list in images: if do_pan_and_scan: images_list, num_crops = self._process_images_for_pan_and_scan( - images=image_list, + images=images_list, do_pan_and_scan=do_pan_and_scan, pan_and_scan_min_crop_size=pan_and_scan_min_crop_size, pan_and_scan_max_num_crops=pan_and_scan_max_num_crops, pan_and_scan_min_ratio_to_activate=pan_and_scan_min_ratio_to_activate, ) else: - num_crops = [[0] for images in images_list] + num_crops = [[0] for _ in images_list] # Group images by size for batched processing processed_image_patches_grouped = {} diff --git a/tests/models/gemma3/test_image_processing_gemma3.py b/tests/models/gemma3/test_image_processing_gemma3.py index 4a26ff87ad..895c04c668 100644 --- a/tests/models/gemma3/test_image_processing_gemma3.py +++ b/tests/models/gemma3/test_image_processing_gemma3.py @@ -143,6 +143,29 @@ class Gemma3ImageProcessingTest(ImageProcessingTestMixin, unittest.TestCase): image_processor = image_processing_class.from_dict(self.image_processor_dict, size=84) self.assertEqual(image_processor.size, {"height": 84, "width": 84}) + def test_without_pan_and_scan(self): + """ + Disable do_pan_and_scan parameter. + """ + for image_processing_class in self.image_processor_list: + # Initialize image_processing + image_processor = image_processing_class.from_dict(self.image_processor_dict, do_pan_and_scan=False) + + # create random PIL images + image_inputs = self.image_processor_tester.prepare_image_inputs(equal_resolution=True) + for image in image_inputs: + self.assertIsInstance(image, Image.Image) + + # Test not batched input + encoded_images = image_processor(image_inputs[0], return_tensors="pt").pixel_values + expected_output_image_shape = (1, 3, 18, 18) + self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape) + + # Test batched + encoded_images = image_processor(image_inputs, return_tensors="pt").pixel_values + expected_output_image_shape = (7, 3, 18, 18) + self.assertEqual(tuple(encoded_images.shape), expected_output_image_shape) + def test_pan_and_scan(self): """ Enables Pan and Scan path by choosing the correct input image resolution. If you are changing