





'''simple docstring'''
import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType






class 							lowercase__     (							__UpperCamelCase       ):
	lowercase__      =      ["""image_processor""", """tokenizer"""]
	lowercase__      =      """LayoutLMv2ImageProcessor"""
	lowercase__      =      ("""LayoutXLMTokenizer""", """LayoutXLMTokenizerFast""")





	def __init__(			self :    Union[str, Any]			,lowerCamelCase__ :    Dict=None			,lowerCamelCase__ :    Optional[Any]=None			,**lowerCamelCase__ :    Union[str, Any]			):







							'''simple docstring'''
							if "feature_extractor" in kwargs:
													warnings.warn(
													    'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
													    ' instead.'			,lowerCamelCase__			,)
													_UpperCamelCase :		List[str]			    =       kwargs.pop('feature_extractor'			)

							_UpperCamelCase :		int			    =       image_processor if image_processor is not None else feature_extractor
							if image_processor is None:
													raise ValueError('You need to specify an `image_processor`.'			)
							if tokenizer is None:
													raise ValueError('You need to specify a `tokenizer`.'			)

							super().__init__(lowerCamelCase__			,lowerCamelCase__			)





	def __call__(			self :    Tuple			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None			,lowerCamelCase__ :    Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]] = None			,lowerCamelCase__ :    Union[List[List[int]], List[List[List[int]]]] = None			,lowerCamelCase__ :    Optional[Union[List[int], List[List[int]]]] = None			,lowerCamelCase__ :    bool = True			,lowerCamelCase__ :    Union[bool, str, PaddingStrategy] = False			,lowerCamelCase__ :    Union[bool, str, TruncationStrategy] = None			,lowerCamelCase__ :    Optional[int] = None			,lowerCamelCase__ :    int = 0			,lowerCamelCase__ :    Optional[int] = None			,lowerCamelCase__ :    Optional[bool] = None			,lowerCamelCase__ :    Optional[bool] = None			,lowerCamelCase__ :    bool = False			,lowerCamelCase__ :    bool = False			,lowerCamelCase__ :    bool = False			,lowerCamelCase__ :    bool = False			,lowerCamelCase__ :    bool = True			,lowerCamelCase__ :    Optional[Union[str, TensorType]] = None			,**lowerCamelCase__ :    Any			,):







							'''simple docstring'''
							# verify input
							if self.image_processor.apply_ocr and (boxes is not None):
													raise ValueError(
													    'You cannot provide bounding boxes '
													    'if you initialized the image processor with apply_ocr set to True.'			)

							if self.image_processor.apply_ocr and (word_labels is not None):
													raise ValueError(
													    'You cannot provide word labels if you initialized the image processor with apply_ocr set to True.'			)

							if return_overflowing_tokens is True and return_offsets_mapping is False:
													raise ValueError('You cannot return overflowing tokens without returning the offsets mapping.'			)

							# first, apply the image processor
							_UpperCamelCase :		List[Any]			    =       self.image_processor(images=lowerCamelCase__			,return_tensors=lowerCamelCase__			)

							# second, apply the tokenizer
							if text is not None and self.image_processor.apply_ocr and text_pair is None:
													if isinstance(lowerCamelCase__			,lowerCamelCase__			):
																			_UpperCamelCase :		Optional[Any]			    =       [text]  # add batch dimension (as the image processor always adds a batch dimension)
													_UpperCamelCase :		Any			    =       features["""words"""]

							_UpperCamelCase :		str			    =       self.tokenizer(
							    text=text if text is not None else features['words']			,text_pair=text_pair if text_pair is not None else None			,boxes=boxes if boxes is not None else features['boxes']			,word_labels=lowerCamelCase__			,add_special_tokens=lowerCamelCase__			,padding=lowerCamelCase__			,truncation=lowerCamelCase__			,max_length=lowerCamelCase__			,stride=lowerCamelCase__			,pad_to_multiple_of=lowerCamelCase__			,return_token_type_ids=lowerCamelCase__			,return_attention_mask=lowerCamelCase__			,return_overflowing_tokens=lowerCamelCase__			,return_special_tokens_mask=lowerCamelCase__			,return_offsets_mapping=lowerCamelCase__			,return_length=lowerCamelCase__			,verbose=lowerCamelCase__			,return_tensors=lowerCamelCase__			,**lowerCamelCase__			,)

							# add pixel values
							_UpperCamelCase :		List[Any]			    =       features.pop('pixel_values'			)
							if return_overflowing_tokens is True:
													_UpperCamelCase :		Optional[Any]			    =       self.get_overflowing_images(lowerCamelCase__			,encoded_inputs['overflow_to_sample_mapping']			)
							_UpperCamelCase :		List[str]			    =       images

							return encoded_inputs





	def      UpperCamelCase_  (			self :    Tuple			,lowerCamelCase__ :    List[str]			,lowerCamelCase__ :    str			):







							'''simple docstring'''
							# in case there's an overflow, ensure each `input_ids` sample is mapped to its corresponding image
							_UpperCamelCase :		List[str]			    =       []
							for sample_idx in overflow_to_sample_mapping:
													images_with_overflow.append(images[sample_idx]			)

							if len(lowerCamelCase__			) != len(lowerCamelCase__			):
													raise ValueError(
													    'Expected length of images to be the same as the length of `overflow_to_sample_mapping`, but got'
													    F' {len(lowerCamelCase__			)} and {len(lowerCamelCase__			)}'			)

							return images_with_overflow





	def      UpperCamelCase_  (			self :    List[Any]			,*lowerCamelCase__ :    List[str]			,**lowerCamelCase__ :    str			):







							'''simple docstring'''
							return self.tokenizer.batch_decode(*lowerCamelCase__			,**lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Any			,*lowerCamelCase__ :    Union[str, Any]			,**lowerCamelCase__ :    Dict			):







							'''simple docstring'''
							return self.tokenizer.decode(*lowerCamelCase__			,**lowerCamelCase__			)





	@property
	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							return ["input_ids", "bbox", "attention_mask", "image"]





	@property
	def      UpperCamelCase_  (			self :    Dict			):







							'''simple docstring'''
							warnings.warn(
							    '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'			,lowerCamelCase__			,)
							return self.image_processor_class





	@property
	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							warnings.warn(
							    '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'			,lowerCamelCase__			,)
							return self.image_processor







'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


snake_case_			:     Optional[int]  	=  {
    'configuration_mask2former': [
        'MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'Mask2FormerConfig',
    ],
}

try:
					if not is_vision_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     int  	=  ['Mask2FormerImageProcessor']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					snake_case_			:     List[Any]  	=  [
					    'MASK2FORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'Mask2FormerForUniversalSegmentation',
					    'Mask2FormerModel',
					    'Mask2FormerPreTrainedModel',
					]

if TYPE_CHECKING:
					from .configuration_maskaformer import MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskaFormerConfig

					try:
										if not is_vision_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .image_processing_maskaformer import MaskaFormerImageProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_maskaformer import (
										    MASK2FORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    MaskaFormerForUniversalSegmentation,
										    MaskaFormerModel,
										    MaskaFormerPreTrainedModel,
										)


else:
					import sys

					snake_case_			:     Dict  	=  _LazyModule(__name__, globals()['__file__'], _import_structure)


