



"""simple docstring"""





from typing import Dict, List, Optional, Tuple, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    flip_channel_order,
    get_resize_output_image_size,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, is_vision_available, logging


if is_vision_available():
  import PIL

if is_torch_available():
  import torch


lowerCamelCase  			=		logging.get_logger(__name__)
class  lowercase__  (       SCREAMING_SNAKE_CASE ):







       '''simple docstring'''


       UpperCamelCase		=	['''pixel_values''']



       def __init__(				self     :    Optional[int]						,							_UpperCAmelCase     :    bool = True						,							_UpperCAmelCase     :    Dict[str, int] = None						,							_UpperCAmelCase     :    PILImageResampling = PILImageResampling.BILINEAR						,							_UpperCAmelCase     :    bool = True						,							_UpperCAmelCase     :    Union[int, float] = 1 / 255						,							_UpperCAmelCase     :    bool = True						,							_UpperCAmelCase     :    Dict[str, int] = None						,							_UpperCAmelCase     :    bool = True						,							**_UpperCAmelCase     :    List[Any]						,							)					->		None:


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase       )
             UpperCAmelCase_     					=				size if size is not None else {"shortest_edge": 224}
             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase						,							default_to_square=_UpperCAmelCase       )
             UpperCAmelCase_     					=				crop_size if crop_size is not None else {"height": 256, "width": 256}
             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase						,							param_name="crop_size"       )

             UpperCAmelCase_     					=				do_resize
             UpperCAmelCase_     					=				size
             UpperCAmelCase_     					=				resample
             UpperCAmelCase_     					=				do_rescale
             UpperCAmelCase_     					=				rescale_factor
             UpperCAmelCase_     					=				do_center_crop
             UpperCAmelCase_     					=				crop_size
             UpperCAmelCase_     					=				do_flip_channel_order



       def 	lowercase__							(				self     :    Optional[int]						,							_UpperCAmelCase     :    np.ndarray						,							_UpperCAmelCase     :    Dict[str, int]						,							_UpperCAmelCase     :    PILImageResampling = PIL.Image.BILINEAR						,							_UpperCAmelCase     :    Optional[Union[str, ChannelDimension]] = None						,							**_UpperCAmelCase     :    str						,							)					->		np.ndarray:


             '''simple docstring'''




             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase						,							default_to_square=_UpperCAmelCase       )
             if "shortest_edge" not in size:
                   raise ValueError(F"""The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"""       )
             UpperCAmelCase_     					=				get_resize_output_image_size(_UpperCAmelCase						,							size=size["shortest_edge"]						,							default_to_square=_UpperCAmelCase       )
             return resize(_UpperCAmelCase						,							size=_UpperCAmelCase						,							resample=_UpperCAmelCase						,							data_format=_UpperCAmelCase						,							**_UpperCAmelCase       )



       def 	lowercase__							(				self     :    int						,							_UpperCAmelCase     :    np.ndarray						,							_UpperCAmelCase     :    Dict[str, int]						,							_UpperCAmelCase     :    Optional[Union[str, ChannelDimension]] = None						,							**_UpperCAmelCase     :    Union[str, Any]						,							)					->		np.ndarray:


             '''simple docstring'''




             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase       )
             if "height" not in size or "width" not in size:
                   raise ValueError(F"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""       )
             return center_crop(_UpperCAmelCase						,							size=(size["height"], size["width"])						,							data_format=_UpperCAmelCase						,							**_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Optional[int]						,							_UpperCAmelCase     :    np.ndarray						,							_UpperCAmelCase     :    Union[int, float]						,							_UpperCAmelCase     :    Optional[Union[str, ChannelDimension]] = None						,							**_UpperCAmelCase     :    Dict						,							)					->		Tuple:


             '''simple docstring'''




             return rescale(_UpperCAmelCase						,							scale=_UpperCAmelCase						,							data_format=_UpperCAmelCase						,							**_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Dict						,							_UpperCAmelCase     :    np.ndarray						,							_UpperCAmelCase     :    Optional[Union[str, ChannelDimension]] = None       )					->		np.ndarray:


             '''simple docstring'''




             return flip_channel_order(_UpperCAmelCase						,							data_format=_UpperCAmelCase       )



       def 	lowercase__							(				self     :    Any						,							_UpperCAmelCase     :    ImageInput						,							_UpperCAmelCase     :    bool = None						,							_UpperCAmelCase     :    Dict[str, int] = None						,							_UpperCAmelCase     :    PILImageResampling = None						,							_UpperCAmelCase     :    bool = None						,							_UpperCAmelCase     :    float = None						,							_UpperCAmelCase     :    bool = None						,							_UpperCAmelCase     :    Dict[str, int] = None						,							_UpperCAmelCase     :    bool = None						,							_UpperCAmelCase     :    Optional[Union[str, TensorType]] = None						,							_UpperCAmelCase     :    ChannelDimension = ChannelDimension.FIRST						,							**_UpperCAmelCase     :    List[str]						,							)					->		PIL.Image.Image:


             '''simple docstring'''




             UpperCAmelCase_     					=				do_resize if do_resize is not None else self.do_resize
             UpperCAmelCase_     					=				resample if resample is not None else self.resample
             UpperCAmelCase_     					=				do_rescale if do_rescale is not None else self.do_rescale
             UpperCAmelCase_     					=				rescale_factor if rescale_factor is not None else self.rescale_factor
             UpperCAmelCase_     					=				do_center_crop if do_center_crop is not None else self.do_center_crop
             UpperCAmelCase_     					=				(
                 do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
             )

             UpperCAmelCase_     					=				size if size is not None else self.size
             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase						,							default_to_square=_UpperCAmelCase       )
             UpperCAmelCase_     					=				crop_size if crop_size is not None else self.crop_size
             UpperCAmelCase_     					=				get_size_dict(_UpperCAmelCase						,							param_name="crop_size"       )

             UpperCAmelCase_     					=				make_list_of_images(_UpperCAmelCase       )

             if not valid_images(_UpperCAmelCase       ):
                   raise ValueError(
                       "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
                       "torch.Tensor, tf.Tensor or jax.ndarray."       )

             if do_resize and size is None:
                   raise ValueError("Size must be specified if do_resize is True."       )

             if do_rescale and rescale_factor is None:
                   raise ValueError("Rescale factor must be specified if do_rescale is True."       )

             if do_center_crop and crop_size is None:
                   raise ValueError("Crop size must be specified if do_center_crop is True."       )

             # All transformations expect numpy arrays.
             UpperCAmelCase_     					=				[to_numpy_array(_UpperCAmelCase       ) for image in images]

             if do_resize:
                   UpperCAmelCase_     					=				[self.resize(image=_UpperCAmelCase						,							size=_UpperCAmelCase						,							resample=_UpperCAmelCase       ) for image in images]

             if do_center_crop:
                   UpperCAmelCase_     					=				[self.center_crop(image=_UpperCAmelCase						,							size=_UpperCAmelCase       ) for image in images]

             if do_rescale:
                   UpperCAmelCase_     					=				[self.rescale(image=_UpperCAmelCase						,							scale=_UpperCAmelCase       ) for image in images]

             # the pretrained checkpoints assume images are BGR, not RGB
             if do_flip_channel_order:
                   UpperCAmelCase_     					=				[self.flip_channel_order(image=_UpperCAmelCase       ) for image in images]

             UpperCAmelCase_     					=				[to_channel_dimension_format(_UpperCAmelCase						,							_UpperCAmelCase       ) for image in images]

             UpperCAmelCase_     					=				{"pixel_values": images}
             return BatchFeature(data=_UpperCAmelCase						,							tensor_type=_UpperCAmelCase       )







       def 	lowercase__							(				self     :    List[Any]						,							_UpperCAmelCase     :    Dict						,							_UpperCAmelCase     :    List[Tuple] = None       )					->		Union[str, Any]:


             '''simple docstring'''




             UpperCAmelCase_     					=				outputs.logits

             # Resize logits and compute semantic segmentation maps
             if target_sizes is not None:
                   if len(_UpperCAmelCase       ) != len(_UpperCAmelCase       ):
                         raise ValueError(
                             "Make sure that you pass in as many target sizes as the batch dimension of the logits"       )

                   if is_torch_tensor(_UpperCAmelCase       ):
                         UpperCAmelCase_     					=				target_sizes.numpy()

                   UpperCAmelCase_     					=				[]

                   for idx in range(len(_UpperCAmelCase       )       ):
                         UpperCAmelCase_     					=				torch.nn.functional.interpolate(
                             logits[idx].unsqueeze(dim=0       )						,							size=target_sizes[idx]						,							mode="bilinear"						,							align_corners=_UpperCAmelCase       )
                         UpperCAmelCase_     					=				resized_logits[0].argmax(dim=0       )
                         semantic_segmentation.append(_UpperCAmelCase       )
             else:
                   UpperCAmelCase_     					=				logits.argmax(dim=1       )
                   UpperCAmelCase_     					=				[semantic_segmentation[i] for i in range(semantic_segmentation.shape[0]       )]

             return semantic_segmentation











from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
		from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


_lowercase		:  Tuple			       =logging.get_logger(__name__)

_lowercase		:  Any			       ={
    """microsoft/deberta-v2-xlarge""": """https://huggingface.co/microsoft/deberta-v2-xlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xxlarge""": """https://huggingface.co/microsoft/deberta-v2-xxlarge/resolve/main/config.json""",
    """microsoft/deberta-v2-xlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xlarge-mnli/resolve/main/config.json"""
    ),
    """microsoft/deberta-v2-xxlarge-mnli""": (
        """https://huggingface.co/microsoft/deberta-v2-xxlarge-mnli/resolve/main/config.json"""
    ),
}






class 						UpperCamelCase_  (  snake_case__							):
					_a      :						int						    =					'deberta-v2'



					def __init__(		self     :     Any       ,      lowerCamelCase     :     Dict=12_81_00       ,      lowerCamelCase     :     List[Any]=15_36       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Union[str, Any]=24       ,      lowerCamelCase     :     Optional[int]=61_44       ,      lowerCamelCase     :     Any="gelu"       ,      lowerCamelCase     :     int=0.1       ,      lowerCamelCase     :     str=0.1       ,      lowerCamelCase     :     Optional[int]=5_12       ,      lowerCamelCase     :     str=0       ,      lowerCamelCase     :     Union[str, Any]=0.02       ,      lowerCamelCase     :     List[str]=1E-7       ,      lowerCamelCase     :     Dict=False       ,      lowerCamelCase     :     List[Any]=-1       ,      lowerCamelCase     :     Union[str, Any]=0       ,      lowerCamelCase     :     Optional[int]=True       ,      lowerCamelCase     :     Optional[int]=None       ,      lowerCamelCase     :     Tuple=0       ,      lowerCamelCase     :     Tuple="gelu"       ,      **lowerCamelCase     :     Optional[int]       ,      ):
							super().__init__(**lowerCamelCase						)

							lowerCamelCase_	:     Any 						=      hidden_size
							lowerCamelCase_	:     Dict 						=      num_hidden_layers
							lowerCamelCase_	:     Optional[int] 						=      num_attention_heads
							lowerCamelCase_	:     Optional[int] 						=      intermediate_size
							lowerCamelCase_	:     str 						=      hidden_act
							lowerCamelCase_	:     int 						=      hidden_dropout_prob
							lowerCamelCase_	:     Tuple 						=      attention_probs_dropout_prob
							lowerCamelCase_	:     Union[str, Any] 						=      max_position_embeddings
							lowerCamelCase_	:     Union[str, Any] 						=      type_vocab_size
							lowerCamelCase_	:     List[Any] 						=      initializer_range
							lowerCamelCase_	:     Optional[Any] 						=      relative_attention
							lowerCamelCase_	:     List[Any] 						=      max_relative_positions
							lowerCamelCase_	:     Optional[int] 						=      pad_token_id
							lowerCamelCase_	:     int 						=      position_biased_input

							# Backwards compatibility
							if type(lowerCamelCase						) == str:
									lowerCamelCase_	:     Dict 						=      [x.strip() for x in pos_att_type.lower().split('|'						)]

							lowerCamelCase_	:     Optional[Any] 						=      pos_att_type
							lowerCamelCase_	:     List[Any] 						=      vocab_size
							lowerCamelCase_	:     Any 						=      layer_norm_eps

							lowerCamelCase_	:     int 						=      kwargs.get('pooler_hidden_size'       ,      lowerCamelCase						)
							lowerCamelCase_	:     Dict 						=      pooler_dropout
							lowerCamelCase_	:     Tuple 						=      pooler_hidden_act






class 						UpperCamelCase_  (  snake_case__							):



					@property
					def   __a     (		self     :     Optional[int]						):
							if self.task == "multiple-choice":
									lowerCamelCase_	:     Optional[Any] 						=      {0: 'batch', 1: 'choice', 2: 'sequence'}
							else:
									lowerCamelCase_	:     Any 						=      {0: 'batch', 1: 'sequence'}
							if self._config.type_vocab_size > 0:
									return OrderedDict(
									    [('input_ids', dynamic_axis), ('attention_mask', dynamic_axis), ('token_type_ids', dynamic_axis)]						)
							else:
									return OrderedDict([('input_ids', dynamic_axis), ('attention_mask', dynamic_axis)]						)



					@property
					def   __a     (		self     :     List[Any]						):
							return 12





					def   __a     (		self     :     Tuple       ,      lowerCamelCase     :     Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     int = -1       ,      lowerCamelCase     :     bool = False       ,      lowerCamelCase     :     Optional["TensorType"] = None       ,      lowerCamelCase     :     int = 3       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     int = 40       ,      lowerCamelCase     :     "PreTrainedTokenizerBase" = None       ,      ):
							lowerCamelCase_	:     Union[str, Any] 						=      super().generate_dummy_inputs(preprocessor=lowerCamelCase       ,      framework=lowerCamelCase						)
							if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
									del dummy_inputs["token_type_ids"]
							return dummy_inputs
