diff --git a/docs/source/en/internal/image_processing_utils.mdx b/docs/source/en/internal/image_processing_utils.mdx index ae4f826517aa..4d5831a12fd6 100644 --- a/docs/source/en/internal/image_processing_utils.mdx +++ b/docs/source/en/internal/image_processing_utils.mdx @@ -22,3 +22,8 @@ Most of those are only useful if you are studying the code of the image processo [[autodoc]] image_transforms.to_pil_image [[autodoc]] image_transforms.resize + + +## ImageProcessorMixin + +[[autodoc]] image_processing_utils.ImageProcessorMixin diff --git a/src/transformers/__init__.py b/src/transformers/__init__.py index db0c2b6dbb9d..dc2a94572fe8 100755 --- a/src/transformers/__init__.py +++ b/src/transformers/__init__.py @@ -634,6 +634,7 @@ name for name in dir(dummy_vision_objects) if not name.startswith("_") ] else: + _import_structure["image_processing_utils"] = ["ImageProcessorMixin"] _import_structure["image_transforms"] = ["resize", "to_pil_image"] _import_structure["image_utils"] = ["ImageFeatureExtractionMixin"] _import_structure["models.beit"].append("BeitFeatureExtractor") @@ -3370,6 +3371,7 @@ except OptionalDependencyNotAvailable: from .utils.dummy_vision_objects import * else: + from .image_processing_utils import ImageProcessorMixin from .image_transforms import resize, to_pil_image from .image_utils import ImageFeatureExtractionMixin from .models.beit import BeitFeatureExtractor diff --git a/src/transformers/image_processing_utils.py b/src/transformers/image_processing_utils.py new file mode 100644 index 000000000000..62a6178d1f80 --- /dev/null +++ b/src/transformers/image_processing_utils.py @@ -0,0 +1,25 @@ +# coding=utf-8 +# Copyright 2022 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .feature_extraction_utils import FeatureExtractionMixin +from .utils import logging + + +logger = logging.get_logger(__name__) + + +# We use aliasing whilst we phase out the old API. Once feature extractors for vision models +# are deprecated, ImageProcessor mixin will be implemented. Any shared logic will be abstracted out. +ImageProcessorMixin = FeatureExtractionMixin diff --git a/src/transformers/utils/__init__.py b/src/transformers/utils/__init__.py index 377932e2d490..af8fc6a06801 100644 --- a/src/transformers/utils/__init__.py +++ b/src/transformers/utils/__init__.py @@ -160,6 +160,7 @@ FLAX_WEIGHTS_INDEX_NAME = "flax_model.msgpack.index.json" CONFIG_NAME = "config.json" FEATURE_EXTRACTOR_NAME = "preprocessor_config.json" +IMAGE_PROCESSOR_NAME = FEATURE_EXTRACTOR_NAME MODEL_CARD_NAME = "modelcard.json" SENTENCEPIECE_UNDERLINE = "▁" diff --git a/src/transformers/utils/dummy_vision_objects.py b/src/transformers/utils/dummy_vision_objects.py index 92a08fb26fb7..359b434253a6 100644 --- a/src/transformers/utils/dummy_vision_objects.py +++ b/src/transformers/utils/dummy_vision_objects.py @@ -3,6 +3,13 @@ from ..utils import DummyObject, requires_backends +class ImageProcessorMixin(metaclass=DummyObject): + _backends = ["vision"] + + def __init__(self, *args, **kwargs): + requires_backends(self, ["vision"]) + + def resize(*args, **kwargs): requires_backends(resize, ["vision"])