From 5e41ff22afdcbf5c9e41e5aa7e0c52cc1f18aeff Mon Sep 17 00:00:00 2001 From: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> Date: Fri, 16 Jan 2026 08:03:16 +0530 Subject: [PATCH 1/2] Fix MobileNet v1/v2 image processor default interpolation to BICUBIC The MobileNet image processors were defaulting to BILINEAR interpolation, but the original timm implementation uses BICUBIC. This change aligns transformers with timm's preprocessing. Contributes to #28180 --- .../models/mobilenet_v1/image_processing_mobilenet_v1.py | 6 +++--- .../models/mobilenet_v2/image_processing_mobilenet_v2.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1.py b/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1.py index 533b3d777412..4cc51c7475ad 100644 --- a/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1.py +++ b/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1.py @@ -54,7 +54,7 @@ class MobileNetV1ImageProcessor(BaseImageProcessor): Size of the image after resizing. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. Can be overridden by `size` in the `preprocess` method. - resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BILINEAR`): + resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`): Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the `preprocess` method. do_center_crop (`bool`, *optional*, defaults to `True`): @@ -87,7 +87,7 @@ def __init__( self, do_resize: bool = True, size: dict[str, int] | None = None, - resample: PILImageResampling = PILImageResampling.BILINEAR, + resample: PILImageResampling = PILImageResampling.BICUBIC, do_center_crop: bool = True, crop_size: dict[str, int] | None = None, do_rescale: bool = True, @@ -194,7 +194,7 @@ def preprocess( Size of the image after resizing. Shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. resample (`PILImageResampling` filter, *optional*, defaults to `self.resample`): - `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BILINEAR`. Only has + `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BICUBIC`. Only has an effect if `do_resize` is set to `True`. do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`): Whether to center crop the image. diff --git a/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2.py b/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2.py index 328bbf9616ef..7b45b7584299 100644 --- a/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2.py +++ b/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2.py @@ -72,7 +72,7 @@ class MobileNetV2ImageProcessor(BaseImageProcessor): Size of the image after resizing. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. Can be overridden by `size` in the `preprocess` method. - resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BILINEAR`): + resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`): Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the `preprocess` method. do_center_crop (`bool`, *optional*, defaults to `True`): @@ -111,7 +111,7 @@ def __init__( self, do_resize: bool = True, size: dict[str, int] | None = None, - resample: PILImageResampling = PILImageResampling.BILINEAR, + resample: PILImageResampling = PILImageResampling.BICUBIC, do_center_crop: bool = True, crop_size: dict[str, int] | None = None, do_rescale: bool = True, @@ -364,7 +364,7 @@ def preprocess( Size of the image after resizing. Shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. resample (`PILImageResampling` filter, *optional*, defaults to `self.resample`): - `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BILINEAR`. Only has + `PILImageResampling` filter to use if resizing the image e.g. `PILImageResampling.BICUBIC`. Only has an effect if `do_resize` is set to `True`. do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`): Whether to center crop the image. From 7418e680724529462176d6edbe5256b08d5713ed Mon Sep 17 00:00:00 2001 From: Vedant Madane <6527493+VedantMadane@users.noreply.github.com> Date: Tue, 20 Jan 2026 01:08:47 +0530 Subject: [PATCH 2/2] fix: update fast processors to BICUBIC for consistency Update MobileNetV1ImageProcessorFast and MobileNetV2ImageProcessorFast to use PILImageResampling.BICUBIC instead of BILINEAR, matching the changes made to the slow image processors. --- .../models/mobilenet_v1/image_processing_mobilenet_v1_fast.py | 2 +- .../models/mobilenet_v2/image_processing_mobilenet_v2_fast.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1_fast.py b/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1_fast.py index d8ea15a8ea64..6b35666f31a5 100644 --- a/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1_fast.py +++ b/src/transformers/models/mobilenet_v1/image_processing_mobilenet_v1_fast.py @@ -22,7 +22,7 @@ @auto_docstring class MobileNetV1ImageProcessorFast(BaseImageProcessorFast): - resample = PILImageResampling.BILINEAR + resample = PILImageResampling.BICUBIC image_mean = IMAGENET_STANDARD_MEAN image_std = IMAGENET_STANDARD_STD size = {"shortest_edge": 256} diff --git a/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2_fast.py b/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2_fast.py index 9537947ca0f9..a4fffffcb9f6 100644 --- a/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2_fast.py +++ b/src/transformers/models/mobilenet_v2/image_processing_mobilenet_v2_fast.py @@ -43,7 +43,7 @@ @auto_docstring class MobileNetV2ImageProcessorFast(BaseImageProcessorFast): - resample = PILImageResampling.BILINEAR + resample = PILImageResampling.BICUBIC image_mean = IMAGENET_STANDARD_MEAN image_std = IMAGENET_STANDARD_STD size = {"shortest_edge": 256}