Skip to content

Commit b5c2aaf

Browse files
committed
accept kwargs in image proc from_pretrained
1 parent a43b36c commit b5c2aaf

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

src/transformers/image_processing_base.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -362,25 +362,15 @@ def from_dict(cls, image_processor_dict: dict[str, Any], **kwargs):
362362
"""
363363
image_processor_dict = image_processor_dict.copy()
364364
return_unused_kwargs = kwargs.pop("return_unused_kwargs", False)
365-
366-
# The `size` parameter is a dict and was previously an int or tuple in feature extractors.
367-
# We set `size` here directly to the `image_processor_dict` so that it is converted to the appropriate
368-
# dict within the image processor and isn't overwritten if `size` is passed in as a kwarg.
369-
if "size" in kwargs and "size" in image_processor_dict:
370-
image_processor_dict["size"] = kwargs.pop("size")
371-
if "crop_size" in kwargs and "crop_size" in image_processor_dict:
372-
image_processor_dict["crop_size"] = kwargs.pop("crop_size")
373-
365+
# remove _from_auto from kwargs before updating the image processor dict
366+
kwargs.pop("_from_auto", None)
367+
image_processor_dict.update(kwargs)
374368
image_processor = cls(**image_processor_dict)
375369

376-
# Update image_processor with kwargs if needed
377-
to_remove = []
378-
for key, value in kwargs.items():
370+
# Remove kwargs that are used to initialize the image processor attributes
371+
for key in list(kwargs):
379372
if hasattr(image_processor, key):
380-
setattr(image_processor, key, value)
381-
to_remove.append(key)
382-
for key in to_remove:
383-
kwargs.pop(key, None)
373+
kwargs.pop(key)
384374

385375
logger.info(f"Image processor {image_processor}")
386376
if return_unused_kwargs:

0 commit comments

Comments
 (0)