




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


__lowerCAmelCase		:				Dict       			=		logging.get_logger(__name__)




class     snake_case__							(snake_case_   ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_       :							Tuple							 =					['''pixel_values''']





				def __init__(      self				:     List[str]					,      __lowerCamelCase				:     str = True					,      __lowerCamelCase				:     Dict = None					,      __lowerCamelCase				:     int = PILImageResampling.BILINEAR					,      __lowerCamelCase				:     str = True					,      __lowerCamelCase				:     Optional[int] = None					,      __lowerCamelCase				:     Optional[Any] = True					,      __lowerCamelCase				:     List[Any] = 1 / 2_55					,      __lowerCamelCase				:     Dict = True					,      __lowerCamelCase				:     str = None					,      __lowerCamelCase				:     Union[str, Any] = None					,      **__lowerCamelCase				:     Optional[int]					,      )					->     None:
							super().__init__(**UpperCamelCase__							)
							a    =			size if size is not None else {"shortest_edge": 2_56}
							a    =			get_size_dict(UpperCamelCase__					,      default_to_square=UpperCamelCase__							)
							a    =			crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
							a    =			get_size_dict(UpperCamelCase__					,      param_name="crop_size"							)
							a    =			do_resize
							a    =			size
							a    =			resample
							a    =			do_center_crop
							a    =			crop_size
							a    =			do_rescale
							a    =			rescale_factor
							a    =			do_normalize
							a    =			image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
							a    =			image_std if image_std is not None else IMAGENET_STANDARD_STD





				def 							__UpperCAmelCase							(      self				:     str					,      __lowerCamelCase				:     Optional[int]					,      __lowerCamelCase				:     int					,      __lowerCamelCase				:     int = PILImageResampling.BICUBIC					,      __lowerCamelCase				:     Tuple = None					,      **__lowerCamelCase				:     Dict					,      )					->     np.ndarray:
							a    =			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()}"""							)
							a    =			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 							__UpperCAmelCase							(      self				:     int					,      __lowerCamelCase				:     str					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     List[Any] = None					,      **__lowerCamelCase				:     str					,      )					->     np.ndarray:
							a    =			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 							__UpperCAmelCase							(      self				:     int					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     Tuple					,      __lowerCamelCase				:     Optional[int] = None					,      **__lowerCamelCase				:     Any							)					->     np.ndarray:
							return rescale(UpperCamelCase__					,      scale=UpperCamelCase__					,      data_format=UpperCamelCase__					,      **UpperCamelCase__							)





				def 							__UpperCAmelCase							(      self				:     str					,      __lowerCamelCase				:     Union[str, Any]					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     Tuple					,      __lowerCamelCase				:     List[str] = None					,      **__lowerCamelCase				:     List[str]					,      )					->     np.ndarray:
							return normalize(UpperCamelCase__					,      mean=UpperCamelCase__					,      std=UpperCamelCase__					,      data_format=UpperCamelCase__					,      **UpperCamelCase__							)





				def 							__UpperCAmelCase							(      self				:     Dict					,      __lowerCamelCase				:     List[str]					,      __lowerCamelCase				:     Dict = None					,      __lowerCamelCase				:     str = None					,      __lowerCamelCase				:     Optional[Any] = None					,      __lowerCamelCase				:     List[Any] = None					,      __lowerCamelCase				:     List[str] = None					,      __lowerCamelCase				:     Optional[Any] = None					,      __lowerCamelCase				:     List[str] = None					,      __lowerCamelCase				:     Union[str, Any] = None					,      __lowerCamelCase				:     Any = None					,      __lowerCamelCase				:     Union[str, Any] = None					,      __lowerCamelCase				:     Union[str, Any] = None					,      __lowerCamelCase				:     int = ChannelDimension.FIRST					,      **__lowerCamelCase				:     Any					,      )					->     int:
							a    =			do_resize if do_resize is not None else self.do_resize
							a    =			size if size is not None else self.size
							a    =			get_size_dict(UpperCamelCase__					,      default_to_square=UpperCamelCase__							)
							a    =			resample if resample is not None else self.resample
							a    =			do_center_crop if do_center_crop is not None else self.do_center_crop
							a    =			crop_size if crop_size is not None else self.crop_size
							a    =			get_size_dict(UpperCamelCase__					,      param_name="crop_size"							)
							a    =			do_rescale if do_rescale is not None else self.do_rescale
							a    =			rescale_factor if rescale_factor is not None else self.rescale_factor
							a    =			do_normalize if do_normalize is not None else self.do_normalize
							a    =			image_mean if image_mean is not None else self.image_mean
							a    =			image_std if image_std is not None else self.image_std

							a    =			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.
							a    =			[to_numpy_array(UpperCamelCase__							) for image in images]

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

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

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

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

							a    =			[to_channel_dimension_format(UpperCamelCase__					,      UpperCamelCase__							) for image in images]

							a    =			{"pixel_values": images}
							return BatchFeature(data=UpperCamelCase__					,      tensor_type=UpperCamelCase__							)





				def 							__UpperCAmelCase							(      self				:     Optional[int]					,      __lowerCamelCase				:     Dict					,      __lowerCamelCase				:     Dict = None							)					->     Any:
							a    =			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__							):
													a    =			target_sizes.numpy()

										a    =			[]

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

							return semantic_segmentation










"""simple docstring"""



from collections import OrderedDict
from typing import Mapping

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


__snake_case   			=    logging.get_logger(__name__)

__snake_case   			=    {
    """facebook/xmod-base""": """https://huggingface.co/facebook/xmod-base/resolve/main/config.json""",
    """facebook/xmod-large-prenorm""": """https://huggingface.co/facebook/xmod-large-prenorm/resolve/main/config.json""",
    """facebook/xmod-base-13-125k""": """https://huggingface.co/facebook/xmod-base-13-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-125k""": """https://huggingface.co/facebook/xmod-base-30-125k/resolve/main/config.json""",
    """facebook/xmod-base-30-195k""": """https://huggingface.co/facebook/xmod-base-30-195k/resolve/main/config.json""",
    """facebook/xmod-base-60-125k""": """https://huggingface.co/facebook/xmod-base-60-125k/resolve/main/config.json""",
    """facebook/xmod-base-60-265k""": """https://huggingface.co/facebook/xmod-base-60-265k/resolve/main/config.json""",
    """facebook/xmod-base-75-125k""": """https://huggingface.co/facebook/xmod-base-75-125k/resolve/main/config.json""",
    """facebook/xmod-base-75-269k""": """https://huggingface.co/facebook/xmod-base-75-269k/resolve/main/config.json""",
}







class _lowerCAmelCase				(      snake_case_	):
   __UpperCAmelCase :       Optional[Any]							  =  '''xmod'''







   def __init__(	self						,	UpperCamelCase__=3_0522						,	UpperCamelCase__=768						,	UpperCamelCase__=12						,	UpperCamelCase__=12						,	UpperCamelCase__=3072						,	UpperCamelCase__="gelu"						,	UpperCamelCase__=0.1						,	UpperCamelCase__=0.1						,	UpperCamelCase__=512						,	UpperCamelCase__=2						,	UpperCamelCase__=0.02						,	UpperCamelCase__=1e-12						,	UpperCamelCase__=1						,	UpperCamelCase__=0						,	UpperCamelCase__=2						,	UpperCamelCase__="absolute"						,	UpperCamelCase__=True						,	UpperCamelCase__=None						,	UpperCamelCase__=False						,	UpperCamelCase__=2						,	UpperCamelCase__=False						,	UpperCamelCase__=True						,	UpperCamelCase__=True						,	UpperCamelCase__=("en_XX",)						,	UpperCamelCase__=None						,	**UpperCamelCase__						,	)	->		int:

       '''simple docstring'''




       super().__init__(pad_token_id=UpperCamelCase__						,	bos_token_id=UpperCamelCase__						,	eos_token_id=UpperCamelCase__						,	**UpperCamelCase__						)

       snake_case    :      List[Any]      					=    vocab_size
       snake_case    :      List[Any]      					=    hidden_size
       snake_case    :      Union[str, Any]      					=    num_hidden_layers
       snake_case    :      Any      					=    num_attention_heads
       snake_case    :      List[str]      					=    hidden_act
       snake_case    :      Union[str, Any]      					=    intermediate_size
       snake_case    :      int      					=    hidden_dropout_prob
       snake_case    :      Any      					=    attention_probs_dropout_prob
       snake_case    :      Optional[int]      					=    max_position_embeddings
       snake_case    :      Tuple      					=    type_vocab_size
       snake_case    :      List[str]      					=    initializer_range
       snake_case    :      int      					=    layer_norm_eps
       snake_case    :      Optional[Any]      					=    position_embedding_type
       snake_case    :      int      					=    use_cache
       snake_case    :      Dict      					=    classifier_dropout
       snake_case    :      Dict      					=    pre_norm
       snake_case    :      Union[str, Any]      					=    adapter_reduction_factor
       snake_case    :      Any      					=    adapter_layer_norm
       snake_case    :      Optional[int]      					=    adapter_reuse_layer_norm
       snake_case    :      List[Any]      					=    ln_before_adapter
       snake_case    :      str      					=    list(UpperCamelCase__						)
       snake_case    :      int      					=    default_language







class _lowerCAmelCase				(      snake_case_	):







   @property
   def  lowerCamelCase		(	self						)	->		Mapping[str, Mapping[int, str]]:

       '''simple docstring'''




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





