






from collections import OrderedDict
from typing import Mapping

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


SCREAMING_SNAKE_CASE__				     =			logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__				     =			{
    '''facebook/xlm-roberta-xl''': '''https://huggingface.co/facebook/xlm-roberta-xl/resolve/main/config.json''',
    '''facebook/xlm-roberta-xxl''': '''https://huggingface.co/facebook/xlm-roberta-xxl/resolve/main/config.json''',
    # See all XLM-RoBERTa-XL models at https://huggingface.co/models?filter=xlm-roberta-xl
}






class 			_UpperCamelCase(       __lowerCamelCase		):
		__SCREAMING_SNAKE_CASE  :       Union[str, Any]							=							'''xlm-roberta-xl'''

		def __init__(					self		:    Union[str, Any]    ,       SCREAMING_SNAKE_CASE__		:    Dict=2_5_0_8_8_0    ,       SCREAMING_SNAKE_CASE__		:    Any=2_5_6_0    ,       SCREAMING_SNAKE_CASE__		:    List[Any]=3_6    ,       SCREAMING_SNAKE_CASE__		:    Tuple=3_2    ,       SCREAMING_SNAKE_CASE__		:    str=1_0_2_4_0    ,       SCREAMING_SNAKE_CASE__		:    Dict="gelu"    ,       SCREAMING_SNAKE_CASE__		:    str=0.1    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=0.1    ,       SCREAMING_SNAKE_CASE__		:    Dict=5_1_4    ,       SCREAMING_SNAKE_CASE__		:    List[str]=1    ,       SCREAMING_SNAKE_CASE__		:    Dict=0.02    ,       SCREAMING_SNAKE_CASE__		:    Union[str, Any]=1e-05    ,       SCREAMING_SNAKE_CASE__		:    int=1    ,       SCREAMING_SNAKE_CASE__		:    Optional[Any]=0    ,       SCREAMING_SNAKE_CASE__		:    List[str]=2    ,       SCREAMING_SNAKE_CASE__		:    int="absolute"    ,       SCREAMING_SNAKE_CASE__		:    Optional[int]=True    ,       SCREAMING_SNAKE_CASE__		:    int=None    ,       **SCREAMING_SNAKE_CASE__		:    List[Any]    ,       ):



					'''simple docstring'''



					super().__init__(pad_token_id=SCREAMING_SNAKE_CASE__    ,       bos_token_id=SCREAMING_SNAKE_CASE__    ,       eos_token_id=SCREAMING_SNAKE_CASE__    ,       **SCREAMING_SNAKE_CASE__    )
					__a						:  Optional[int]									=     vocab_size
					__a						:  int									=     hidden_size
					__a						:  Any									=     num_hidden_layers
					__a						:  Optional[Any]									=     num_attention_heads
					__a						:  Any									=     hidden_act
					__a						:  int									=     intermediate_size
					__a						:  int									=     hidden_dropout_prob
					__a						:  Dict									=     attention_probs_dropout_prob
					__a						:  int									=     max_position_embeddings
					__a						:  Tuple									=     type_vocab_size
					__a						:  Any									=     initializer_range
					__a						:  Any									=     layer_norm_eps
					__a						:  List[str]									=     position_embedding_type
					__a						:  Dict									=     use_cache
					__a						:  Dict									=     classifier_dropout






class 			_UpperCamelCase(       __lowerCamelCase		):

		@property
		def    __lowerCAmelCase  (					self		:    List[Any]    ):



					'''simple docstring'''



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








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


UpperCAmelCase_							:					Optional[int]		 =   logging.get_logger(__name__)






class      lowerCamelCase_      (	_lowercase	):
	_lowercase		:   List[str]     					=				['''pixel_values''']




	def __init__(     self						:     Dict					,      __A						:     bool = True					,      __A						:     Optional[Dict[str, int]] = None					,      __A						:     PILImageResampling = PILImageResampling.BILINEAR					,      __A						:     bool = True					,      __A						:     Dict[str, int] = None					,      __A						:     bool = True					,      __A						:     Union[int, float] = 1 / 255					,      __A						:     bool = True					,      __A						:     Optional[Union[float, List[float]]] = None					,      __A						:     Optional[Union[float, List[float]]] = None					,      **__A						:     int					,      ):
		super().__init__(**__A							)
		__A :			Union[str, Any]		    =			size if size is not None else {"""shortest_edge""": 256}
		__A :			Dict		    =			get_size_dict(__A					,      default_to_square=__A							)
		__A :			str		    =			crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
		__A :			int		    =			get_size_dict(__A					,      param_name="""crop_size"""							)
		__A :			str		    =			do_resize
		__A :			Dict		    =			size
		__A :			Any		    =			resample
		__A :			Optional[Any]		    =			do_center_crop
		__A :			List[str]		    =			crop_size
		__A :			Optional[int]		    =			do_rescale
		__A :			int		    =			rescale_factor
		__A :			Union[str, Any]		    =			do_normalize
		__A :			int		    =			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
		__A :			Dict		    =			image_std if image_std is not None else IMAGENET_STANDARD_STD




	def        lowerCAmelCase_       (     self						:     Optional[Any]					,      __A						:     np.ndarray					,      __A						:     Dict[str, int]					,      __A						:     PILImageResampling = PILImageResampling.BICUBIC					,      __A						:     Optional[Union[str, ChannelDimension]] = None					,      **__A						:     List[Any]					,      ):
		__A :			str		    =			get_size_dict(__A					,      default_to_square=__A							)
		if "shortest_edge" not in size:
			raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""							)
		__A :			Dict		    =			get_resize_output_image_size(__A					,      size=size["""shortest_edge"""]					,      default_to_square=__A							)
		return resize(__A					,      size=__A					,      resample=__A					,      data_format=__A					,      **__A							)




	def        lowerCAmelCase_       (     self						:     Tuple					,      __A						:     np.ndarray					,      __A						:     Dict[str, int]					,      __A						:     Optional[Union[str, ChannelDimension]] = None					,      **__A						:     str					,      ):
		__A :			str		    =			get_size_dict(__A							)
		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(__A					,      size=(size["""height"""], size["""width"""])					,      data_format=__A					,      **__A							)




	def        lowerCAmelCase_       (     self						:     List[str]					,      __A						:     np.ndarray					,      __A						:     float					,      __A						:     Optional[Union[str, ChannelDimension]] = None					,      **__A						:     Optional[int]							):
		return rescale(__A					,      scale=__A					,      data_format=__A					,      **__A							)




	def        lowerCAmelCase_       (     self						:     Any					,      __A						:     np.ndarray					,      __A						:     Union[float, List[float]]					,      __A						:     Union[float, List[float]]					,      __A						:     Optional[Union[str, ChannelDimension]] = None					,      **__A						:     Tuple					,      ):
		return normalize(__A					,      mean=__A					,      std=__A					,      data_format=__A					,      **__A							)




	def        lowerCAmelCase_       (     self						:     int					,      __A						:     ImageInput					,      __A						:     Optional[bool] = None					,      __A						:     Dict[str, int] = None					,      __A						:     PILImageResampling = None					,      __A						:     bool = None					,      __A						:     Dict[str, int] = None					,      __A						:     Optional[bool] = None					,      __A						:     Optional[float] = None					,      __A						:     Optional[bool] = None					,      __A						:     Optional[Union[float, List[float]]] = None					,      __A						:     Optional[Union[float, List[float]]] = None					,      __A						:     Optional[Union[str, TensorType]] = None					,      __A						:     Union[str, ChannelDimension] = ChannelDimension.FIRST					,      **__A						:     Optional[int]					,      ):
		__A :			List[str]		    =			do_resize if do_resize is not None else self.do_resize
		__A :			Any		    =			size if size is not None else self.size
		__A :			Union[str, Any]		    =			get_size_dict(__A					,      default_to_square=__A							)
		__A :			Tuple		    =			resample if resample is not None else self.resample
		__A :			Tuple		    =			do_center_crop if do_center_crop is not None else self.do_center_crop
		__A :			List[Any]		    =			crop_size if crop_size is not None else self.crop_size
		__A :			int		    =			get_size_dict(__A					,      param_name="""crop_size"""							)
		__A :			Tuple		    =			do_rescale if do_rescale is not None else self.do_rescale
		__A :			Optional[Any]		    =			rescale_factor if rescale_factor is not None else self.rescale_factor
		__A :			Optional[int]		    =			do_normalize if do_normalize is not None else self.do_normalize
		__A :			Optional[int]		    =			image_mean if image_mean is not None else self.image_mean
		__A :			List[str]		    =			image_std if image_std is not None else self.image_std

		__A :			Union[str, Any]		    =			make_list_of_images(__A							)

		if not valid_images(__A							):
			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.
		__A :			Union[str, Any]		    =			[to_numpy_array(__A							) for image in images]

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

		if do_center_crop:
			__A :			Optional[Any]		    =			[self.center_crop(image=__A					,      size=__A							) for image in images]

		if do_rescale:
			__A :			List[Any]		    =			[self.rescale(image=__A					,      scale=__A							) for image in images]

		if do_normalize:
			__A :			Any		    =			[self.normalize(image=__A					,      mean=__A					,      std=__A							) for image in images]

		__A :			int		    =			[to_channel_dimension_format(__A					,      __A							) for image in images]

		__A :			Tuple		    =			{"""pixel_values""": images}
		return BatchFeature(data=__A					,      tensor_type=__A							)




	def        lowerCAmelCase_       (     self						:     int					,      __A						:     List[str]					,      __A						:     List[Tuple] = None							):
		__A :			Union[str, Any]		    =			outputs.logits

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

			if is_torch_tensor(__A							):
				__A :			str		    =			target_sizes.numpy()

			__A :			int		    =			[]

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

		return semantic_segmentation





