Skip to content

Commit 953196a

Browse files
EricWienerqubvel
andauthored
Fix typing issues with SigLip2 (#37356)
* Fix issues * Fix comment --------- Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
1 parent aaf129c commit 953196a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/transformers/image_processing_utils_fast.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,12 @@ def preprocess(self, images: ImageInput, **kwargs: Unpack[DefaultFastImageProces
691691

692692
# torch resize uses interpolation instead of resample
693693
resample = kwargs.pop("resample")
694+
695+
# Check if resample is an int before checking if it's an instance of PILImageResampling
696+
# because if pillow < 9.1.0, resample is an int and PILImageResampling is a module.
697+
# Checking PILImageResampling will fail with error `TypeError: isinstance() arg 2 must be a type or tuple of types`.
694698
kwargs["interpolation"] = (
695-
pil_torch_interpolation_mapping[resample] if isinstance(resample, (PILImageResampling, int)) else resample
699+
pil_torch_interpolation_mapping[resample] if isinstance(resample, (int, PILImageResampling)) else resample
696700
)
697701

698702
# Pop kwargs that are not needed in _preprocess

src/transformers/models/siglip2/image_processing_siglip2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Siglip2ImageProcessor(BaseImageProcessor):
163163
def __init__(
164164
self,
165165
do_resize: bool = True,
166-
resample: PILImageResampling = PILImageResampling.BILINEAR,
166+
resample: "PILImageResampling" = PILImageResampling.BILINEAR,
167167
do_rescale: bool = True,
168168
rescale_factor: float = 1 / 255,
169169
do_normalize: bool = True,
@@ -195,7 +195,7 @@ def preprocess(
195195
self,
196196
images: ImageInput,
197197
do_resize: Optional[bool] = None,
198-
resample: Optional[PILImageResampling] = None,
198+
resample: Optional["PILImageResampling"] = None,
199199
do_rescale: Optional[bool] = None,
200200
rescale_factor: Optional[float] = None,
201201
do_normalize: Optional[bool] = None,

0 commit comments

Comments
 (0)