


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


__UpperCamelCase				:				Dict  				= logging.get_logger(__name__)

class 					__magic_name__		(   __lowerCAmelCase):
     A:						Optional[Any]								=					['pixel_values']


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





      '''simple docstring'''






      super().__init__(**lowerCamelCase__	)
      UpperCamelCase__    :			List[str]      				=      size if size is not None else {'''shortest_edge''': 224}
      UpperCamelCase__    :			Optional[Any]      				=      get_size_dict(lowerCamelCase__							,		default_to_square=lowerCamelCase__	)
      UpperCamelCase__    :			Tuple      				=      crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
      UpperCamelCase__    :			Tuple      				=      get_size_dict(lowerCamelCase__							,		param_name='''crop_size'''	)

      UpperCamelCase__    :			int      				=      do_resize
      UpperCamelCase__    :			Optional[int]      				=      size
      UpperCamelCase__    :			str      				=      resample
      UpperCamelCase__    :			Any      				=      do_rescale
      UpperCamelCase__    :			str      				=      rescale_factor
      UpperCamelCase__    :			Dict      				=      do_center_crop
      UpperCamelCase__    :			Optional[Any]      				=      crop_size
      UpperCamelCase__    :			Optional[int]      				=      do_flip_channel_order


     def    UpperCAmelCase__		(					self							:   Any							,		lowerCamelCase__							:   List[Any]							,		lowerCamelCase__							:   Dict							,		lowerCamelCase__							:   Optional[int] = PIL.Image.BILINEAR							,		lowerCamelCase__							:   List[str] = None							,		**lowerCamelCase__							:   int							,		)     ->					np.ndarray:





      '''simple docstring'''






      UpperCamelCase__    :			str      				=      get_size_dict(lowerCamelCase__							,		default_to_square=lowerCamelCase__	)
      if "shortest_edge" not in size:
       raise ValueError(F"The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}"	)
      UpperCamelCase__    :			List[Any]      				=      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    UpperCAmelCase__		(					self							:   Any							,		lowerCamelCase__							:   Dict							,		lowerCamelCase__							:   int							,		lowerCamelCase__							:   Tuple = None							,		**lowerCamelCase__							:   Optional[int]							,		)     ->					np.ndarray:





      '''simple docstring'''






      UpperCamelCase__    :			int      				=      get_size_dict(lowerCamelCase__	)
      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(lowerCamelCase__							,		size=(size['''height'''], size['''width'''])							,		data_format=lowerCamelCase__							,		**lowerCamelCase__	)


     def    UpperCAmelCase__		(					self							:   List[str]							,		lowerCamelCase__							:   Dict							,		lowerCamelCase__							:   Optional[int]							,		lowerCamelCase__							:   Dict = None							,		**lowerCamelCase__							:   Optional[Any]							,		)     ->					Any:





      '''simple docstring'''






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


     def    UpperCAmelCase__		(					self							:   List[Any]							,		lowerCamelCase__							:   Optional[Any]							,		lowerCamelCase__							:   Union[str, Any] = None	)     ->					np.ndarray:





      '''simple docstring'''






      return flip_channel_order(lowerCamelCase__							,		data_format=lowerCamelCase__	)


     def    UpperCAmelCase__		(					self							:   Optional[Any]							,		lowerCamelCase__							:   List[Any]							,		lowerCamelCase__							:   Optional[Any] = None							,		lowerCamelCase__							:   Optional[Any] = None							,		lowerCamelCase__							:   Tuple = None							,		lowerCamelCase__							:   Tuple = None							,		lowerCamelCase__							:   Optional[int] = None							,		lowerCamelCase__							:   Optional[int] = None							,		lowerCamelCase__							:   Union[str, Any] = None							,		lowerCamelCase__							:   List[str] = None							,		lowerCamelCase__							:   Dict = None							,		lowerCamelCase__							:   Tuple = ChannelDimension.FIRST							,		**lowerCamelCase__							:   Tuple							,		)     ->					PIL.Image.Image:





      '''simple docstring'''






      UpperCamelCase__    :			str      				=      do_resize if do_resize is not None else self.do_resize
      UpperCamelCase__    :			int      				=      resample if resample is not None else self.resample
      UpperCamelCase__    :			Dict      				=      do_rescale if do_rescale is not None else self.do_rescale
      UpperCamelCase__    :			int      				=      rescale_factor if rescale_factor is not None else self.rescale_factor
      UpperCamelCase__    :			Tuple      				=      do_center_crop if do_center_crop is not None else self.do_center_crop
      UpperCamelCase__    :			Optional[int]      				=      (
          do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
      )

      UpperCamelCase__    :			Union[str, Any]      				=      size if size is not None else self.size
      UpperCamelCase__    :			Optional[Any]      				=      get_size_dict(lowerCamelCase__							,		default_to_square=lowerCamelCase__	)
      UpperCamelCase__    :			Dict      				=      crop_size if crop_size is not None else self.crop_size
      UpperCamelCase__    :			Dict      				=      get_size_dict(lowerCamelCase__							,		param_name='''crop_size'''	)

      UpperCamelCase__    :			Tuple      				=      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_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__    :			Any      				=      [to_numpy_array(lowerCamelCase__	) for image in images]

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

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

      if do_rescale:
       UpperCamelCase__    :			Union[str, Any]      				=      [self.rescale(image=lowerCamelCase__							,		scale=lowerCamelCase__	) for image in images]

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

      UpperCamelCase__    :			Any      				=      [to_channel_dimension_format(lowerCamelCase__							,		lowerCamelCase__	) for image in images]

      UpperCamelCase__    :			Any      				=      {'''pixel_values''': images}
      return BatchFeature(data=lowerCamelCase__							,		tensor_type=lowerCamelCase__	)


     def    UpperCAmelCase__		(					self							:   List[str]							,		lowerCamelCase__							:   Union[str, Any]							,		lowerCamelCase__							:   Optional[Any] = None	)     ->					List[Any]:





      '''simple docstring'''






      UpperCamelCase__    :			Dict      				=      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__    :			int      				=      target_sizes.numpy()

       UpperCamelCase__    :			Tuple      				=      []

       for idx in range(len(lowerCamelCase__	)	):
        UpperCamelCase__    :			int      				=      torch.nn.functional.interpolate(
            logits[idx].unsqueeze(dim=0	)							,		size=target_sizes[idx]							,		mode='''bilinear'''							,		align_corners=lowerCamelCase__	)
        UpperCamelCase__    :			List[Any]      				=      resized_logits[0].argmax(dim=0	)
        semantic_segmentation.append(lowerCamelCase__	)
      else:
       UpperCamelCase__    :			Optional[int]      				=      logits.argmax(dim=1	)
       UpperCamelCase__    :			str      				=      [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


lowercase_		       =  logging.get_logger(__name__)

lowercase_		       =  {
    "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 __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Any          =       'xmod'



 def __init__(self ,   A=30_522 ,   A=768 ,   A=12 ,   A=12 ,   A=3_072 ,   A="gelu" ,   A=0.1 ,   A=0.1 ,   A=512 ,   A=2 ,   A=0.02 ,   A=1E-12 ,   A=1 ,   A=0 ,   A=2 ,   A="absolute" ,   A=True ,   A=None ,   A=False ,   A=2 ,   A=False ,   A=True ,   A=True ,   A=("en_XX",) ,   A=None ,   **A ,   )    ->     List[str]:


      """simple docstring"""



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

      _a      =  vocab_size
      _a      =  hidden_size
      _a      =  num_hidden_layers
      _a      =  num_attention_heads
      _a      =  hidden_act
      _a      =  intermediate_size
      _a      =  hidden_dropout_prob
      _a      =  attention_probs_dropout_prob
      _a      =  max_position_embeddings
      _a      =  type_vocab_size
      _a      =  initializer_range
      _a      =  layer_norm_eps
      _a      =  position_embedding_type
      _a      =  use_cache
      _a      =  classifier_dropout
      _a      =  pre_norm
      _a      =  adapter_reduction_factor
      _a      =  adapter_layer_norm
      _a      =  adapter_reuse_layer_norm
      _a      =  ln_before_adapter
      _a      =  list(A       )
      _a      =  default_language






class __A			(  A						):



 '''simple docstring'''







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


      """simple docstring"""



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



