Fast image processor (#28847)
* Draft fast image processors * Draft working fast version * py3.8 compatible cache * Enable loading fast image processors through auto * Tidy up; rescale behaviour based on input type * Enable tests for fast image processors * Smarter rescaling * Don't default to Fast * Safer imports * Add necessary Pillow requirement * Woops * Add AutoImageProcessor test * Fix up * Fix test for imagegpt * Fix test * Review comments * Add warning for TF and JAX input types * Rearrange * Return transforms * NumpyToTensor transformation * Rebase - include changes from upstream in ImageProcessingMixin * Safe typing * Fix up * convert mean/std to tesnor to rescale * Don't store transforms in state * Fix up * Update src/transformers/image_processing_utils_fast.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/auto/image_processing_auto.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/auto/image_processing_auto.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/auto/image_processing_auto.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Warn if fast image processor available * Update src/transformers/models/vit/image_processing_vit_fast.py * Transpose incoming numpy images to be in CHW format * Update mapping names based on packages, auto set fast to None * Fix up * Fix * Add AutoImageProcessor.from_pretrained(checkpoint, use_fast=True) test * Update src/transformers/models/vit/image_processing_vit_fast.py Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com> * Add equivalence and speed tests * Fix up --------- Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: Pavel Iakubovskii <qubvel@gmail.com>
This commit is contained in:
@@ -27,8 +27,10 @@ from transformers import (
|
||||
AutoImageProcessor,
|
||||
CLIPConfig,
|
||||
CLIPImageProcessor,
|
||||
ViTImageProcessor,
|
||||
ViTImageProcessorFast,
|
||||
)
|
||||
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER
|
||||
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_torchvision, require_vision
|
||||
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))
|
||||
@@ -133,6 +135,23 @@ class AutoImageProcessorTest(unittest.TestCase):
|
||||
):
|
||||
_ = AutoImageProcessor.from_pretrained("hf-internal-testing/config-no-model")
|
||||
|
||||
@require_vision
|
||||
@require_torchvision
|
||||
def test_use_fast_selection(self):
|
||||
checkpoint = "hf-internal-testing/tiny-random-vit"
|
||||
|
||||
# Slow image processor is selected by default
|
||||
image_processor = AutoImageProcessor.from_pretrained(checkpoint)
|
||||
self.assertIsInstance(image_processor, ViTImageProcessor)
|
||||
|
||||
# Fast image processor is selected when use_fast=True
|
||||
image_processor = AutoImageProcessor.from_pretrained(checkpoint, use_fast=True)
|
||||
self.assertIsInstance(image_processor, ViTImageProcessorFast)
|
||||
|
||||
# Slow image processor is selected when use_fast=False
|
||||
image_processor = AutoImageProcessor.from_pretrained(checkpoint, use_fast=False)
|
||||
self.assertIsInstance(image_processor, ViTImageProcessor)
|
||||
|
||||
def test_from_pretrained_dynamic_image_processor(self):
|
||||
# If remote code is not set, we will time out when asking whether to load the model.
|
||||
with self.assertRaises(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user