Skip to content

Commit a34922d

Browse files
🚨Fix MobileViT image processor default interpolation to BICUBIC (#43024)
* Fix MobileViT image processor default interpolation to BICUBIC The original MobileViT implementation (Apple's ml-cvnets) and timm both use BICUBIC interpolation for image preprocessing. Updates both slow and fast image processors to match. Contributes to #28180 * Remove copy substitution - code now matches source --------- Co-authored-by: Yoni Gozlan <[email protected]>
1 parent 98578fc commit a34922d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/transformers/models/mobilevit/image_processing_mobilevit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class MobileViTImageProcessor(BaseImageProcessor):
7979
size (`dict[str, int]` *optional*, defaults to `{"shortest_edge": 224}`):
8080
Controls the size of the output image after resizing. Can be overridden by the `size` parameter in the
8181
`preprocess` method.
82-
resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`):
82+
resample (`PILImageResampling`, *optional*, defaults to `Resampling.BICUBIC`):
8383
Defines the resampling filter to use if resizing the image. Can be overridden by the `resample` parameter
8484
in the `preprocess` method.
8585
do_rescale (`bool`, *optional*, defaults to `True`):
@@ -112,7 +112,7 @@ def __init__(
112112
self,
113113
do_resize: bool = True,
114114
size: Optional[dict[str, int]] = None,
115-
resample: PILImageResampling = PILImageResampling.BILINEAR,
115+
resample: PILImageResampling = PILImageResampling.BICUBIC,
116116
do_rescale: bool = True,
117117
rescale_factor: Union[int, float] = 1 / 255,
118118
do_center_crop: bool = True,
@@ -137,12 +137,12 @@ def __init__(
137137
self.do_flip_channel_order = do_flip_channel_order
138138
self.do_reduce_labels = do_reduce_labels
139139

140-
# Copied from transformers.models.mobilenet_v1.image_processing_mobilenet_v1.MobileNetV1ImageProcessor.resize with PILImageResampling.BICUBIC->PILImageResampling.BILINEAR
140+
# Copied from transformers.models.mobilenet_v1.image_processing_mobilenet_v1.MobileNetV1ImageProcessor.resize
141141
def resize(
142142
self,
143143
image: np.ndarray,
144144
size: dict[str, int],
145-
resample: PILImageResampling = PILImageResampling.BILINEAR,
145+
resample: PILImageResampling = PILImageResampling.BICUBIC,
146146
data_format: Optional[Union[str, ChannelDimension]] = None,
147147
input_data_format: Optional[Union[str, ChannelDimension]] = None,
148148
**kwargs,
@@ -156,7 +156,7 @@ def resize(
156156
Image to resize.
157157
size (`dict[str, int]`):
158158
Size of the output image.
159-
resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BILINEAR`):
159+
resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
160160
Resampling filter to use when resiizing the image.
161161
data_format (`str` or `ChannelDimension`, *optional*):
162162
The channel dimension format of the image. If not provided, it will be the same as the input image.

src/transformers/models/mobilevit/image_processing_mobilevit_fast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
@auto_docstring
4444
class MobileViTImageProcessorFast(BaseImageProcessorFast):
45-
resample = PILImageResampling.BILINEAR
45+
resample = PILImageResampling.BICUBIC
4646
size = {"shortest_edge": 224}
4747
default_to_square = False
4848
crop_size = {"height": 256, "width": 256}

0 commit comments

Comments
 (0)