
"""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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_torch_available, is_torch_tensor, logging


if is_torch_available():
      import torch


SCREAMING_SNAKE_CASE			  =  logging.get_logger(__name__)



class 	__a	(   _lowerCAmelCase						):
       UpperCamelCase_		:       Union[str, Any]				=      ['''pixel_values''']






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







              """simple docstring"""
              super().__init__(**UpperCAmelCase_      )
              UpperCamelCase       			=		size if size is not None else {"shortest_edge": 256}
              UpperCamelCase       			=		get_size_dict(UpperCAmelCase_							,   default_to_square=UpperCAmelCase_      )
              UpperCamelCase       			=		crop_size if crop_size is not None else {"height": 224, "width": 224}
              UpperCamelCase       			=		get_size_dict(UpperCAmelCase_							,   param_name="crop_size"      )
              UpperCamelCase       			=		do_resize
              UpperCamelCase       			=		size
              UpperCamelCase       			=		resample
              UpperCamelCase       			=		do_center_crop
              UpperCamelCase       			=		crop_size
              UpperCamelCase       			=		do_rescale
              UpperCamelCase       			=		rescale_factor
              UpperCamelCase       			=		do_normalize
              UpperCamelCase       			=		image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
              UpperCamelCase       			=		image_std if image_std is not None else IMAGENET_STANDARD_STD






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]							,   UpperCAmelCase_			:				np.ndarray							,   UpperCAmelCase_			:				Dict[str, int]							,   UpperCAmelCase_			:				PILImageResampling = PILImageResampling.BICUBIC							,   UpperCAmelCase_			:				Optional[Union[str, ChannelDimension]] = None							,   **UpperCAmelCase_			:				Union[str, Any]							,   )->	np.ndarray:







              """simple docstring"""
              UpperCamelCase       			=		get_size_dict(UpperCAmelCase_							,   default_to_square=UpperCAmelCase_      )
              if "shortest_edge" not in size:
                     raise ValueError(f"The `size` parameter 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 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]							,   UpperCAmelCase_			:				np.ndarray							,   UpperCAmelCase_			:				Dict[str, int]							,   UpperCAmelCase_			:				Optional[Union[str, ChannelDimension]] = None							,   **UpperCAmelCase_			:				str							,   )->	np.ndarray:







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






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any							,   UpperCAmelCase_			:				np.ndarray							,   UpperCAmelCase_			:				float							,   UpperCAmelCase_			:				Optional[Union[str, ChannelDimension]] = None							,   **UpperCAmelCase_			:				Tuple      )->	np.ndarray:







              """simple docstring"""
              return rescale(UpperCAmelCase_							,   scale=UpperCAmelCase_							,   data_format=UpperCAmelCase_							,   **UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]							,   UpperCAmelCase_			:				np.ndarray							,   UpperCAmelCase_			:				Union[float, List[float]]							,   UpperCAmelCase_			:				Union[float, List[float]]							,   UpperCAmelCase_			:				Optional[Union[str, ChannelDimension]] = None							,   **UpperCAmelCase_			:				Any							,   )->	np.ndarray:







              """simple docstring"""
              return normalize(UpperCAmelCase_							,   mean=UpperCAmelCase_							,   std=UpperCAmelCase_							,   data_format=UpperCAmelCase_							,   **UpperCAmelCase_      )






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Dict							,   UpperCAmelCase_			:				ImageInput							,   UpperCAmelCase_			:				Optional[bool] = None							,   UpperCAmelCase_			:				Dict[str, int] = None							,   UpperCAmelCase_			:				PILImageResampling = None							,   UpperCAmelCase_			:				bool = None							,   UpperCAmelCase_			:				Dict[str, int] = None							,   UpperCAmelCase_			:				Optional[bool] = None							,   UpperCAmelCase_			:				Optional[float] = None							,   UpperCAmelCase_			:				Optional[bool] = None							,   UpperCAmelCase_			:				Optional[Union[float, List[float]]] = None							,   UpperCAmelCase_			:				Optional[Union[float, List[float]]] = None							,   UpperCAmelCase_			:				Optional[Union[str, TensorType]] = None							,   UpperCAmelCase_			:				Union[str, ChannelDimension] = ChannelDimension.FIRST							,   **UpperCAmelCase_			:				Tuple							,   )->	Dict:







              """simple docstring"""
              UpperCamelCase       			=		do_resize if do_resize is not None else self.do_resize
              UpperCamelCase       			=		size if size is not None else self.size
              UpperCamelCase       			=		get_size_dict(UpperCAmelCase_							,   default_to_square=UpperCAmelCase_      )
              UpperCamelCase       			=		resample if resample is not None else self.resample
              UpperCamelCase       			=		do_center_crop if do_center_crop is not None else self.do_center_crop
              UpperCamelCase       			=		crop_size if crop_size is not None else self.crop_size
              UpperCamelCase       			=		get_size_dict(UpperCAmelCase_							,   param_name="crop_size"      )
              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_normalize if do_normalize is not None else self.do_normalize
              UpperCamelCase       			=		image_mean if image_mean is not None else self.image_mean
              UpperCamelCase       			=		image_std if image_std is not None else self.image_std

              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_center_crop and crop_size is None:
                     raise ValueError("Crop size must be specified if do_center_crop is True."      )

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

              if do_normalize and (image_mean is None or image_std is None):
                     raise ValueError("Image mean and std must be specified if do_normalize 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]

              if do_normalize:
                     UpperCamelCase       			=		[self.normalize(image=UpperCAmelCase_							,   mean=UpperCAmelCase_							,   std=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 						_SCREAMING_SNAKE_CASE							(	self			:				Dict							,   UpperCAmelCase_			:				List[str]							,   UpperCAmelCase_			:				List[Tuple] = None      )->	List[str]:







              """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







"""simple docstring"""


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


SCREAMING_SNAKE_CASE			  =  logging.get_logger(__name__)

SCREAMING_SNAKE_CASE			  =  {
    """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 	__a	(   _lowerCAmelCase						):
       UpperCamelCase_		:       Any				=      '''deberta-v2'''






       def __init__(	self			:				Dict							,   UpperCAmelCase_			:				Optional[int]=128_100							,   UpperCAmelCase_			:				List[str]=1_536							,   UpperCAmelCase_			:				List[str]=24							,   UpperCAmelCase_			:				int=24							,   UpperCAmelCase_			:				int=6_144							,   UpperCAmelCase_			:				Optional[Any]="gelu"							,   UpperCAmelCase_			:				Tuple=0.1							,   UpperCAmelCase_			:				int=0.1							,   UpperCAmelCase_			:				Optional[int]=512							,   UpperCAmelCase_			:				Optional[int]=0							,   UpperCAmelCase_			:				Dict=0.02							,   UpperCAmelCase_			:				Optional[Any]=1e-7							,   UpperCAmelCase_			:				str=False							,   UpperCAmelCase_			:				Tuple=-1							,   UpperCAmelCase_			:				Optional[int]=0							,   UpperCAmelCase_			:				List[str]=True							,   UpperCAmelCase_			:				Any=None							,   UpperCAmelCase_			:				Optional[Any]=0							,   UpperCAmelCase_			:				Optional[Any]="gelu"							,   **UpperCAmelCase_			:				Optional[int]							,   )->	int:







              """simple docstring"""
              super().__init__(**UpperCAmelCase_      )

              UpperCamelCase       			=		hidden_size
              UpperCamelCase       			=		num_hidden_layers
              UpperCamelCase       			=		num_attention_heads
              UpperCamelCase       			=		intermediate_size
              UpperCamelCase       			=		hidden_act
              UpperCamelCase       			=		hidden_dropout_prob
              UpperCamelCase       			=		attention_probs_dropout_prob
              UpperCamelCase       			=		max_position_embeddings
              UpperCamelCase       			=		type_vocab_size
              UpperCamelCase       			=		initializer_range
              UpperCamelCase       			=		relative_attention
              UpperCamelCase       			=		max_relative_positions
              UpperCamelCase       			=		pad_token_id
              UpperCamelCase       			=		position_biased_input

              # Backwards compatibility
              if type(UpperCAmelCase_      ) == str:
                     UpperCamelCase       			=		[x.strip() for x in pos_att_type.lower().split("|"      )]

              UpperCamelCase       			=		pos_att_type
              UpperCamelCase       			=		vocab_size
              UpperCamelCase       			=		layer_norm_eps

              UpperCamelCase       			=		kwargs.get("pooler_hidden_size"							,   UpperCAmelCase_      )
              UpperCamelCase       			=		pooler_dropout
              UpperCamelCase       			=		pooler_hidden_act





class 	__a	(   _lowerCAmelCase						):






       @property
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Mapping[str, Mapping[int, str]]:







              """simple docstring"""
              if self.task == "multiple-choice":
                     UpperCamelCase       			=		{0: "batch", 1: "choice", 2: "sequence"}
              else:
                     UpperCamelCase       			=		{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 						_SCREAMING_SNAKE_CASE							(	self			:				Union[str, Any]      )->	int:







              """simple docstring"""
              return 12






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]							,   UpperCAmelCase_			:				Union["PreTrainedTokenizerBase", "FeatureExtractionMixin"]							,   UpperCAmelCase_			:				int = -1							,   UpperCAmelCase_			:				int = -1							,   UpperCAmelCase_			:				int = -1							,   UpperCAmelCase_			:				bool = False							,   UpperCAmelCase_			:				Optional["TensorType"] = None							,   UpperCAmelCase_			:				int = 3							,   UpperCAmelCase_			:				int = 40							,   UpperCAmelCase_			:				int = 40							,   UpperCAmelCase_			:				"PreTrainedTokenizerBase" = None							,   )->	Mapping[str, Any]:







              """simple docstring"""
              UpperCamelCase       			=		super().generate_dummy_inputs(preprocessor=UpperCAmelCase_							,   framework=UpperCAmelCase_      )
              if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
                     del dummy_inputs["token_type_ids"]
              return dummy_inputs





