Fall back to slow image processor in ImageProcessingAuto when no fast processor available (#34785)

* refactor image_processing_auto logic

* fix fast image processor tests

* Fix tests fast vit image processor

* Add safeguard when use_fast True and torchvision not available

* change default use_fast back to None, add warnings

* remove debugging print

* call get_image_processor_class_from_name once
This commit is contained in:
Yoni Gozlan
2024-12-15 14:00:36 -05:00
committed by GitHub
parent ca03842cdc
commit 5615a39369
8 changed files with 72 additions and 37 deletions

View File

@@ -228,14 +228,15 @@ class ImageProcessingTestMixin:
self.assertEqual(image_processor_second.to_dict(), image_processor_first.to_dict())
def test_image_processor_save_load_with_autoimageprocessor(self):
for image_processing_class in self.image_processor_list:
for i, image_processing_class in enumerate(self.image_processor_list):
image_processor_first = image_processing_class(**self.image_processor_dict)
with tempfile.TemporaryDirectory() as tmpdirname:
saved_file = image_processor_first.save_pretrained(tmpdirname)[0]
check_json_file_has_correct_format(saved_file)
image_processor_second = AutoImageProcessor.from_pretrained(tmpdirname)
use_fast = i == 1
image_processor_second = AutoImageProcessor.from_pretrained(tmpdirname, use_fast=use_fast)
self.assertEqual(image_processor_second.to_dict(), image_processor_first.to_dict())