Skip to content

Commit

Permalink
call get_image_processor_class_from_name once
Browse files Browse the repository at this point in the history
  • Loading branch information
yonigozlan committed Dec 15, 2024
1 parent f107a66 commit 95d039a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/transformers/models/auto/image_processing_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95d039a

Please sign in to comment.