Skip to content

Commit 1b743cd

Browse files
🚨 Fix EfficientNet image processor default interpolation to BICUBIC (#42956)
Fix EfficientNet image processor default interpolation to BICUBIC The original EfficientNet implementation uses BICUBIC interpolation for image preprocessing, but both EfficientNetImageProcessor and EfficientNetImageProcessorFast defaulted to NEAREST. This change aligns the default with the original implementation. Reference: https://github.com/tensorflow/tpu/blob/master/models/official/efficientnet/preprocessing.py Fixes part of #28180
1 parent 8fe3ec2 commit 1b743cd

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

‎src/transformers/models/efficientnet/image_processing_efficientnet.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class EfficientNetImageProcessor(BaseImageProcessor):
6666
`do_resize` in `preprocess`.
6767
size (`dict[str, int]` *optional*, defaults to `{"height": 346, "width": 346}`):
6868
Size of the image after `resize`. Can be overridden by `size` in `preprocess`.
69-
resample (`PILImageResampling` filter, *optional*, defaults to 0):
69+
resample (`PILImageResampling` filter, *optional*, defaults to `Resampling.BICUBIC`):
7070
Resampling filter to use if resizing the image. Can be overridden by `resample` in `preprocess`.
7171
do_center_crop (`bool`, *optional*, defaults to `False`):
7272
Whether to center crop the image. If the input size is smaller than `crop_size` along any edge, the image
@@ -102,7 +102,7 @@ def __init__(
102102
self,
103103
do_resize: bool = True,
104104
size: Optional[dict[str, int]] = None,
105-
resample: PILImageResampling = PIL.Image.NEAREST,
105+
resample: PILImageResampling = PILImageResampling.BICUBIC,
106106
do_center_crop: bool = False,
107107
crop_size: Optional[dict[str, int]] = None,
108108
rescale_factor: Union[int, float] = 1 / 255,
@@ -133,12 +133,11 @@ def __init__(
133133
self.image_std = image_std if image_std is not None else IMAGENET_STANDARD_STD
134134
self.include_top = include_top
135135

136-
# Copied from transformers.models.vit.image_processing_vit.ViTImageProcessor.resize with PILImageResampling.BILINEAR->PILImageResampling.NEAREST
137136
def resize(
138137
self,
139138
image: np.ndarray,
140139
size: dict[str, int],
141-
resample: PILImageResampling = PILImageResampling.NEAREST,
140+
resample: PILImageResampling = PILImageResampling.BICUBIC,
142141
data_format: Optional[Union[str, ChannelDimension]] = None,
143142
input_data_format: Optional[Union[str, ChannelDimension]] = None,
144143
**kwargs,
@@ -151,8 +150,8 @@ def resize(
151150
Image to resize.
152151
size (`dict[str, int]`):
153152
Dictionary in the format `{"height": int, "width": int}` specifying the size of the output image.
154-
resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.NEAREST`):
155-
`PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.NEAREST`.
153+
resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling.BICUBIC`):
154+
`PILImageResampling` filter to use when resizing the image e.g. `PILImageResampling.BICUBIC`.
156155
data_format (`ChannelDimension` or `str`, *optional*):
157156
The channel dimension format for the output image. If unset, the channel dimension format of the input
158157
image is used. Can be one of:

‎src/transformers/models/efficientnet/image_processing_efficientnet_fast.py‎

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

3434
@auto_docstring
3535
class EfficientNetImageProcessorFast(BaseImageProcessorFast):
36-
resample = PILImageResampling.NEAREST
36+
resample = PILImageResampling.BICUBIC
3737
image_mean = IMAGENET_STANDARD_MEAN
3838
image_std = IMAGENET_STANDARD_STD
3939
size = {"height": 346, "width": 346}

0 commit comments

Comments
 (0)