From 95d039aef5559b9d9c2502f160ccf754febfad52 Mon Sep 17 00:00:00 2001 From: yonigozlan Date: Sun, 15 Dec 2024 18:43:30 +0000 Subject: [PATCH] call get_image_processor_class_from_name once --- src/transformers/models/auto/image_processing_auto.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/transformers/models/auto/image_processing_auto.py b/src/transformers/models/auto/image_processing_auto.py index 350b3401cceadd..db25591eaa3544 100644 --- a/src/transformers/models/auto/image_processing_auto.py +++ b/src/transformers/models/auto/image_processing_auto.py @@ -501,13 +501,17 @@ def from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs): if use_fast: if not image_processor_type.endswith("Fast"): image_processor_type += "Fast" - image_processor_class = get_image_processor_class_from_name(image_processor_type) - if image_processor_class is None: + for _, image_processors in IMAGE_PROCESSOR_MAPPING_NAMES.items(): + if image_processor_type in image_processors: + break + else: + image_processor_type = image_processor_type[:-4] + use_fast = False logger.warning_once( "`use_fast` is set to `True` but the image processor class does not have a fast version. " " Falling back to the slow version." ) - image_processor_class = get_image_processor_class_from_name(image_processor_type[:-4]) + image_processor_class = get_image_processor_class_from_name(image_processor_type) else: image_processor_type = ( image_processor_type[:-4] if image_processor_type.endswith("Fast") else image_processor_type