Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2022 The HuggingFace Inc. team.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""16Processor class for ViLT.17"""18 19import warnings20from typing import Optional21 22from ...processing_utils import ImagesKwargs, ProcessingKwargs, ProcessorMixin23 24 25class ViltImagesKwargs(ImagesKwargs):26 size_divisor: Optional[int]27 28 29class ViltProcessorKwargs(ProcessingKwargs, total=False):30 images_kwargs: ViltImagesKwargs31 _defaults = {32 "text_kwargs": {33 "add_special_tokens": True,34 "padding": False,35 "stride": 0,36 "return_overflowing_tokens": False,37 "return_special_tokens_mask": False,38 "return_offsets_mapping": False,39 "return_length": False,40 "verbose": True,41 },42 }43 44 45class ViltProcessor(ProcessorMixin):46 r"""47 Constructs a ViLT processor which wraps a BERT tokenizer and ViLT image processor into a single processor.48 49 [`ViltProcessor`] offers all the functionalities of [`ViltImageProcessor`] and [`BertTokenizerFast`]. See the50 docstring of [`~ViltProcessor.__call__`] and [`~ViltProcessor.decode`] for more information.51 52 Args:53 image_processor (`ViltImageProcessor`, *optional*):54 An instance of [`ViltImageProcessor`]. The image processor is a required input.55 tokenizer (`BertTokenizerFast`, *optional*):56 An instance of ['BertTokenizerFast`]. The tokenizer is a required input.57 """58 59 attributes = ["image_processor", "tokenizer"]60 image_processor_class = "ViltImageProcessor"61 tokenizer_class = ("BertTokenizer", "BertTokenizerFast")62 valid_processor_kwargs = ViltProcessorKwargs63 64 def __init__(self, image_processor=None, tokenizer=None, **kwargs):65 feature_extractor = None66 if "feature_extractor" in kwargs:67 warnings.warn(68 "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"69 " instead.",70 FutureWarning,71 )72 feature_extractor = kwargs.pop("feature_extractor")73 74 image_processor = image_processor if image_processor is not None else feature_extractor75 super().__init__(image_processor, tokenizer)76 self.current_processor = self.image_processor77 78 @property79 def feature_extractor_class(self):80 warnings.warn(81 "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.",82 FutureWarning,83 )84 return self.image_processor_class85 86 @property87 def feature_extractor(self):88 warnings.warn(89 "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.",90 FutureWarning,91 )92 return self.image_processor93 94 95__all__ = ["ViltProcessor"]96 