





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


lowercase__		:     Tuple			=							logging.get_logger(__name__)
class 							__lowerCAmelCase	(       __magic_name__					):






       """simple docstring"""
       _snake_case      :	Any									=       ['pixel_values']





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

            '''simple docstring'''




            super().__init__(**lowerCAmelCase__	)
            _UpperCamelCase							       =			size if size is not None else {'''shortest_edge''': 256}
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					default_to_square=lowerCAmelCase__	)
            _UpperCamelCase							       =			crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					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 snake_case__		(				self  :						List[str]			,					lowerCAmelCase__  :						np.ndarray			,					lowerCAmelCase__  :						Dict[str, int]			,					lowerCAmelCase__  :						PILImageResampling = PILImageResampling.BICUBIC			,					lowerCAmelCase__  :						Optional[Union[str, ChannelDimension]] = None			,					**lowerCAmelCase__  :						Optional[Any]			,					)       ->	np.ndarray:

            '''simple docstring'''




            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__			,					default_to_square=lowerCAmelCase__	)
            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(lowerCAmelCase__			,					size=size['''shortest_edge''']			,					default_to_square=lowerCAmelCase__	)
            return resize(lowerCAmelCase__			,					size=lowerCAmelCase__			,					resample=lowerCAmelCase__			,					data_format=lowerCAmelCase__			,					**lowerCAmelCase__	)





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

            '''simple docstring'''




            _UpperCamelCase							       =			get_size_dict(lowerCAmelCase__	)
            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(lowerCAmelCase__			,					size=(size['''height'''], size['''width'''])			,					data_format=lowerCAmelCase__			,					**lowerCAmelCase__	)





       def snake_case__		(				self  :						str			,					lowerCAmelCase__  :						np.ndarray			,					lowerCAmelCase__  :						float			,					lowerCAmelCase__  :						Optional[Union[str, ChannelDimension]] = None			,					**lowerCAmelCase__  :						Optional[int]	)       ->	np.ndarray:

            '''simple docstring'''




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





       def snake_case__		(				self  :						Dict			,					lowerCAmelCase__  :						np.ndarray			,					lowerCAmelCase__  :						Union[float, List[float]]			,					lowerCAmelCase__  :						Union[float, List[float]]			,					lowerCAmelCase__  :						Optional[Union[str, ChannelDimension]] = None			,					**lowerCAmelCase__  :						Optional[int]			,					)       ->	np.ndarray:

            '''simple docstring'''




            return normalize(lowerCAmelCase__			,					mean=lowerCAmelCase__			,					std=lowerCAmelCase__			,					data_format=lowerCAmelCase__			,					**lowerCAmelCase__	)





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

            '''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(lowerCAmelCase__			,					default_to_square=lowerCAmelCase__	)
            _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(lowerCAmelCase__			,					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(lowerCAmelCase__	)

            if not valid_images(lowerCAmelCase__	):
                 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(lowerCAmelCase__	) for image in images]

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

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

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

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

            _UpperCamelCase							       =			[to_channel_dimension_format(lowerCAmelCase__			,					lowerCAmelCase__	) for image in images]

            _UpperCamelCase							       =			{'''pixel_values''': images}
            return BatchFeature(data=lowerCAmelCase__			,					tensor_type=lowerCAmelCase__	)







       def snake_case__		(				self  :						List[str]			,					lowerCAmelCase__  :						Dict			,					lowerCAmelCase__  :						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(lowerCAmelCase__	) != len(lowerCAmelCase__	):
                      raise ValueError(
                          '''Make sure that you pass in as many target sizes as the batch dimension of the logits'''	)

                 if is_torch_tensor(lowerCAmelCase__	):
                      _UpperCamelCase							       =			target_sizes.numpy()

                 _UpperCamelCase							       =			[]

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

            return semantic_segmentation









from typing import Mapping

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


SCREAMING_SNAKE_CASE:     List[Any]									= logging.get_logger(__name__)

SCREAMING_SNAKE_CASE:     Optional[Any]									= {
    '''google/umt5-small''': '''https://huggingface.co/google/umt5-small/resolve/main/config.json''',
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}



class    lowercase_		(SCREAMING_SNAKE_CASE__ ):
						lowerCAmelCase__			      ="umt5"
						lowerCAmelCase__			      =["past_key_values"]



						def __init__(			self	:   Optional[Any]					,							snake_case__	:   Union[str, Any]=25_01_12					,							snake_case__	:   Optional[int]=5_12					,							snake_case__	:   Optional[Any]=64					,							snake_case__	:   str=10_24					,							snake_case__	:   Dict=8					,							snake_case__	:   Union[str, Any]=None					,							snake_case__	:   List[Any]=6					,							snake_case__	:   List[Any]=32					,							snake_case__	:   List[Any]=1_28					,							snake_case__	:   Optional[int]=0.1					,							snake_case__	:   List[str]=1e-6					,							snake_case__	:   Optional[Any]=1.0					,							snake_case__	:   Optional[int]="gated-gelu"					,							snake_case__	:   Any=True					,							snake_case__	:   List[Any]=True					,							snake_case__	:   List[str]="T5Tokenizer"					,							snake_case__	:   List[str]=True					,							snake_case__	:   Tuple=0					,							snake_case__	:   Optional[int]=1					,							snake_case__	:   List[str]=0					,							**snake_case__	:   Any					,							):

								"""simple docstring"""

								super().__init__(
								    is_encoder_decoder=snake_case__					,							tokenizer_class=snake_case__					,							tie_word_embeddings=snake_case__					,							pad_token_id=snake_case__					,							eos_token_id=snake_case__					,							decoder_start_token_id=snake_case__					,							**snake_case__					,							)
								SCREAMING_SNAKE_CASE_					      =							vocab_size
								SCREAMING_SNAKE_CASE_					      =							d_model
								SCREAMING_SNAKE_CASE_					      =							d_kv
								SCREAMING_SNAKE_CASE_					      =							d_ff
								SCREAMING_SNAKE_CASE_					      =							num_layers
								SCREAMING_SNAKE_CASE_					      =							(
								    num_decoder_layers if num_decoder_layers is not None else self.num_layers
								)  # default = symmetry
								SCREAMING_SNAKE_CASE_					      =							num_heads
								SCREAMING_SNAKE_CASE_					      =							relative_attention_num_buckets
								SCREAMING_SNAKE_CASE_					      =							relative_attention_max_distance
								SCREAMING_SNAKE_CASE_					      =							dropout_rate
								SCREAMING_SNAKE_CASE_					      =							layer_norm_epsilon
								SCREAMING_SNAKE_CASE_					      =							initializer_factor
								SCREAMING_SNAKE_CASE_					      =							feed_forward_proj
								SCREAMING_SNAKE_CASE_					      =							use_cache

								SCREAMING_SNAKE_CASE_					      =							self.feed_forward_proj.split('-'  )
								SCREAMING_SNAKE_CASE_					      =							act_info[-1]
								SCREAMING_SNAKE_CASE_					      =							act_info[0] == 'gated'

								if len(snake_case__  ) > 1 and act_info[0] != "gated" or len(snake_case__  ) > 2:
										raise ValueError(
										    f'''`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer.'''
										    'Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '
										    '\'gated-gelu\' or \'relu\''  )

								if feed_forward_proj == "gated-gelu":
										SCREAMING_SNAKE_CASE_					      =							'gelu_new'



						@property
						def 	__a					(			self	:   Optional[Any]  ):

								"""simple docstring"""

								return self.d_model



						@property
						def 	__a					(			self	:   Union[str, Any]  ):

								"""simple docstring"""

								return self.num_heads






						@property
						def 	__a					(			self	:   Optional[Any]  ):

								"""simple docstring"""

								return self.num_layers



class    lowercase_		(SCREAMING_SNAKE_CASE__ ):



						@property
						# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
						def 	__a					(			self	:   int  ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_					      =							{
								    'input_ids': {0: 'batch', 1: 'encoder_sequence'},
								    'attention_mask': {0: 'batch', 1: 'encoder_sequence'},
								}
								if self.use_past:
										SCREAMING_SNAKE_CASE_					      =							'past_encoder_sequence + sequence'
										SCREAMING_SNAKE_CASE_					      =							{0: 'batch'}
										SCREAMING_SNAKE_CASE_					      =							{0: 'batch', 1: 'past_decoder_sequence + sequence'}
								else:
										SCREAMING_SNAKE_CASE_					      =							{0: 'batch', 1: 'decoder_sequence'}
										SCREAMING_SNAKE_CASE_					      =							{0: 'batch', 1: 'decoder_sequence'}

								if self.use_past:
										self.fill_with_past_key_values_(snake_case__					,							direction='inputs'  )

								return common_inputs



						@property
						# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
						def 	__a					(			self	:   Union[str, Any]  ):

								"""simple docstring"""

								return 13






						@property
						def 	__a					(			self	:   Dict  ):

								"""simple docstring"""

								return 5e-4