



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


lowercase_		       =  logging.get_logger(__name__)






class __A			(  A						):



 '''simple docstring'''







 __lowerCamelCase    :       Optional[Any]          =       ['pixel_values']



 def __init__(self ,   A = True ,   A = None ,   A = PILImageResampling.BILINEAR ,   A = True ,   A = 1 / 255 ,   A = True ,   A = None ,   A = True ,   **A ,   )    ->     None:


      """simple docstring"""



      super().__init__(**A       )
      _a      =  size if size is not None else {'''shortest_edge''': 224}
      _a      =  get_size_dict(A ,   default_to_square=A       )
      _a      =  crop_size if crop_size is not None else {'''height''': 256, '''width''': 256}
      _a      =  get_size_dict(A ,   param_name='''crop_size'''       )

      _a      =  do_resize
      _a      =  size
      _a      =  resample
      _a      =  do_rescale
      _a      =  rescale_factor
      _a      =  do_center_crop
      _a      =  crop_size
      _a      =  do_flip_channel_order



 def 					a__  (self ,   A ,   A ,   A = PIL.Image.BILINEAR ,   A = None ,   **A ,   )    ->     np.ndarray:


      """simple docstring"""



      _a      =  get_size_dict(A ,   default_to_square=A       )
      if "shortest_edge" not in size:
           raise ValueError(f'''The `size` dictionary must contain the key `shortest_edge`. Got {size.keys()}'''       )
      _a      =  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 					a__  (self ,   A ,   A ,   A = None ,   **A ,   )    ->     np.ndarray:


      """simple docstring"""



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



 def 					a__  (self ,   A ,   A ,   A = None ,   **A ,   )    ->     Any:


      """simple docstring"""



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



 def 					a__  (self ,   A ,   A = None       )    ->     np.ndarray:


      """simple docstring"""



      return flip_channel_order(A ,   data_format=A       )



 def 					a__  (self ,   A ,   A = None ,   A = None ,   A = None ,   A = None ,   A = None ,   A = None ,   A = None ,   A = None ,   A = None ,   A = ChannelDimension.FIRST ,   **A ,   )    ->     PIL.Image.Image:


      """simple docstring"""



      _a      =  do_resize if do_resize is not None else self.do_resize
      _a      =  resample if resample is not None else self.resample
      _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_center_crop if do_center_crop is not None else self.do_center_crop
      _a      =  (
          do_flip_channel_order if do_flip_channel_order is not None else self.do_flip_channel_order
      )

      _a      =  size if size is not None else self.size
      _a      =  get_size_dict(A ,   default_to_square=A       )
      _a      =  crop_size if crop_size is not None else self.crop_size
      _a      =  get_size_dict(A ,   param_name='''crop_size'''       )

      _a      =  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_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.
      _a      =  [to_numpy_array(A       ) for image in images]

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

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

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

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

      _a      =  [to_channel_dimension_format(A ,   A       ) for image in images]

      _a      =  {'''pixel_values''': images}
      return BatchFeature(data=A ,   tensor_type=A       )



 def 					a__  (self ,   A ,   A = None       )    ->     List[Any]:


      """simple docstring"""



      _a      =  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      =  target_sizes.numpy()

           _a      =  []

           for idx in range(len(A       )       ):
                _a      =  torch.nn.functional.interpolate(
                    logits[idx].unsqueeze(dim=0       ) ,   size=target_sizes[idx] ,   mode='''bilinear''' ,   align_corners=A       )
                _a      =  resized_logits[0].argmax(dim=0       )
                semantic_segmentation.append(A       )
      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


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),
          ]       )



