


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


__a	 =      logging.get_logger(__name__)






class 	__lowercase					(	UpperCamelCase_	):
      UpperCamelCase										=							['''pixel_values''']





      def __init__(		self    :       Dict       ,							__lowerCamelCase    :       Dict = True       ,							__lowerCamelCase    :       Dict = None       ,							__lowerCamelCase    :       Dict = PILImageResampling.BILINEAR       ,							__lowerCamelCase    :       str = True       ,							__lowerCamelCase    :       List[str] = None       ,							__lowerCamelCase    :       int = True       ,							__lowerCamelCase    :       Dict = 1 / 2_5_5       ,							__lowerCamelCase    :       Dict = True       ,							__lowerCamelCase    :       str = None       ,							__lowerCamelCase    :       Optional[Any] = None       ,							**__lowerCamelCase    :       Optional[int]       ,							)     -> None:






         """simple docstring"""







         super().__init__(**__SCREAMING_SNAKE_CASE							)
         UpperCAmelCase      					=  size if size is not None else {'''shortest_edge''': 2_5_6}
         UpperCAmelCase      					=  get_size_dict(__SCREAMING_SNAKE_CASE       ,							default_to_square=__SCREAMING_SNAKE_CASE							)
         UpperCAmelCase      					=  crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
         UpperCAmelCase      					=  get_size_dict(__SCREAMING_SNAKE_CASE       ,							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 							_lowercase					(		self    :       List[Any]       ,							__lowerCamelCase    :       List[Any]       ,							__lowerCamelCase    :       Optional[Any]       ,							__lowerCamelCase    :       Dict = PILImageResampling.BICUBIC       ,							__lowerCamelCase    :       Dict = None       ,							**__lowerCamelCase    :       Optional[Any]       ,							)     -> np.ndarray:






         """simple docstring"""







         UpperCAmelCase      					=  get_size_dict(__SCREAMING_SNAKE_CASE       ,							default_to_square=__SCREAMING_SNAKE_CASE							)
         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(__SCREAMING_SNAKE_CASE       ,							size=size["""shortest_edge"""]       ,							default_to_square=__SCREAMING_SNAKE_CASE							)
         return resize(__SCREAMING_SNAKE_CASE       ,							size=__SCREAMING_SNAKE_CASE       ,							resample=__SCREAMING_SNAKE_CASE       ,							data_format=__SCREAMING_SNAKE_CASE       ,							**__SCREAMING_SNAKE_CASE							)





      def 							_lowercase					(		self    :       Union[str, Any]       ,							__lowerCamelCase    :       Optional[int]       ,							__lowerCamelCase    :       int       ,							__lowerCamelCase    :       Any = None       ,							**__lowerCamelCase    :       Optional[Any]       ,							)     -> np.ndarray:






         """simple docstring"""







         UpperCAmelCase      					=  get_size_dict(__SCREAMING_SNAKE_CASE							)
         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(__SCREAMING_SNAKE_CASE       ,							size=(size["""height"""], size["""width"""])       ,							data_format=__SCREAMING_SNAKE_CASE       ,							**__SCREAMING_SNAKE_CASE							)





      def 							_lowercase					(		self    :       str       ,							__lowerCamelCase    :       Dict       ,							__lowerCamelCase    :       Optional[int]       ,							__lowerCamelCase    :       Optional[int] = None       ,							**__lowerCamelCase    :       List[Any]							)     -> np.ndarray:






         """simple docstring"""







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





      def 							_lowercase					(		self    :       Any       ,							__lowerCamelCase    :       Optional[Any]       ,							__lowerCamelCase    :       List[Any]       ,							__lowerCamelCase    :       Optional[int]       ,							__lowerCamelCase    :       str = None       ,							**__lowerCamelCase    :       List[Any]       ,							)     -> np.ndarray:






         """simple docstring"""







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





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






         """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(__SCREAMING_SNAKE_CASE       ,							default_to_square=__SCREAMING_SNAKE_CASE							)
         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(__SCREAMING_SNAKE_CASE       ,							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(__SCREAMING_SNAKE_CASE							)

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

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

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

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

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

         UpperCAmelCase      					=  [to_channel_dimension_format(__SCREAMING_SNAKE_CASE       ,							__SCREAMING_SNAKE_CASE							) for image in images]

         UpperCAmelCase      					=  {'''pixel_values''': images}
         return BatchFeature(data=__SCREAMING_SNAKE_CASE       ,							tensor_type=__SCREAMING_SNAKE_CASE							)





      def 							_lowercase					(		self    :       int       ,							__lowerCamelCase    :       Tuple       ,							__lowerCamelCase    :       str = None							)     -> Tuple:






         """simple docstring"""







         UpperCAmelCase      					=  outputs.logits

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

            if is_torch_tensor(__SCREAMING_SNAKE_CASE							):
               UpperCAmelCase      					=  target_sizes.numpy()

            UpperCAmelCase      					=  []

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

         return semantic_segmentation





import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase  =logging.get_logger(__name__)

lowerCamelCase  ={
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	'''wav2vec2'''






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=7_6_8    ,    __SCREAMING_SNAKE_CASE=1_2    ,    __SCREAMING_SNAKE_CASE=1_2    ,    __SCREAMING_SNAKE_CASE=3_0_7_2    ,    __SCREAMING_SNAKE_CASE="gelu"    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=1e-5    ,    __SCREAMING_SNAKE_CASE="group"    ,    __SCREAMING_SNAKE_CASE="gelu"    ,    __SCREAMING_SNAKE_CASE=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)    ,    __SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)    ,    __SCREAMING_SNAKE_CASE=(1_0, 3, 3, 3, 3, 2, 2)    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=1_2_8    ,    __SCREAMING_SNAKE_CASE=1_6    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=0.05    ,    __SCREAMING_SNAKE_CASE=1_0    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=1_0    ,    __SCREAMING_SNAKE_CASE=0    ,    __SCREAMING_SNAKE_CASE=3_2_0    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=1_0_0    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE="sum"    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=2_5_6    ,    __SCREAMING_SNAKE_CASE=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)    ,    __SCREAMING_SNAKE_CASE=(5, 3, 3, 1, 1)    ,    __SCREAMING_SNAKE_CASE=(1, 2, 3, 1, 1)    ,    __SCREAMING_SNAKE_CASE=5_1_2    ,    __SCREAMING_SNAKE_CASE=0    ,    __SCREAMING_SNAKE_CASE=1    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=False    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=2    ,    __SCREAMING_SNAKE_CASE=3    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE=None    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> str:




           """simple docstring"""







           super().__init__(**__SCREAMING_SNAKE_CASE    ,    pad_token_id=__SCREAMING_SNAKE_CASE    ,    bos_token_id=__SCREAMING_SNAKE_CASE    ,    eos_token_id=__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : str											=					hidden_size
           UpperCamelCase__     : List[Any]											=					feat_extract_norm
           UpperCamelCase__     : Union[str, Any]											=					feat_extract_activation
           UpperCamelCase__     : Union[str, Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Dict											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Tuple											=					conv_bias
           UpperCamelCase__     : Optional[Any]											=					num_conv_pos_embeddings
           UpperCamelCase__     : Tuple											=					num_conv_pos_embedding_groups
           UpperCamelCase__     : Tuple											=					len(self.conv_dim	)
           UpperCamelCase__     : Optional[Any]											=					num_hidden_layers
           UpperCamelCase__     : Union[str, Any]											=					intermediate_size
           UpperCamelCase__     : Union[str, Any]											=					hidden_act
           UpperCamelCase__     : List[Any]											=					num_attention_heads
           UpperCamelCase__     : Optional[int]											=					hidden_dropout
           UpperCamelCase__     : Tuple											=					attention_dropout
           UpperCamelCase__     : List[Any]											=					activation_dropout
           UpperCamelCase__     : Optional[int]											=					feat_proj_dropout
           UpperCamelCase__     : int											=					final_dropout
           UpperCamelCase__     : str											=					layerdrop
           UpperCamelCase__     : Dict											=					layer_norm_eps
           UpperCamelCase__     : str											=					initializer_range
           UpperCamelCase__     : List[Any]											=					vocab_size
           UpperCamelCase__     : Dict											=					do_stable_layer_norm
           UpperCamelCase__     : Dict											=					use_weighted_layer_sum

           if (
               (len(self.conv_stride	) != self.num_feat_extract_layers)
               or (len(self.conv_kernel	) != self.num_feat_extract_layers)
               or (len(self.conv_dim	) != self.num_feat_extract_layers)
           ):
                 raise ValueError(
                     '''Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='''
                     ''' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='''
                     F''' {len(self.conv_dim	)}`, `len(config.conv_stride) = {len(self.conv_stride	)}`,'''
                     F''' `len(config.conv_kernel) = {len(self.conv_kernel	)}`.'''	)

           # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
           UpperCamelCase__     : Tuple											=					apply_spec_augment
           UpperCamelCase__     : str											=					mask_time_prob
           UpperCamelCase__     : Tuple											=					mask_time_length
           UpperCamelCase__     : Optional[Any]											=					mask_time_min_masks
           UpperCamelCase__     : str											=					mask_feature_prob
           UpperCamelCase__     : List[str]											=					mask_feature_length
           UpperCamelCase__     : Optional[Any]											=					mask_feature_min_masks

           # parameters for pretraining with codevector quantized representations
           UpperCamelCase__     : Dict											=					num_codevectors_per_group
           UpperCamelCase__     : Optional[int]											=					num_codevector_groups
           UpperCamelCase__     : Dict											=					contrastive_logits_temperature
           UpperCamelCase__     : List[Any]											=					feat_quantizer_dropout
           UpperCamelCase__     : List[Any]											=					num_negatives
           UpperCamelCase__     : Tuple											=					codevector_dim
           UpperCamelCase__     : List[str]											=					proj_codevector_dim
           UpperCamelCase__     : Tuple											=					diversity_loss_weight

           # ctc loss
           UpperCamelCase__     : List[str]											=					ctc_loss_reduction
           UpperCamelCase__     : Optional[Any]											=					ctc_zero_infinity

           # adapter
           UpperCamelCase__     : List[Any]											=					add_adapter
           UpperCamelCase__     : Any											=					adapter_kernel_size
           UpperCamelCase__     : Tuple											=					adapter_stride
           UpperCamelCase__     : Tuple											=					num_adapter_layers
           UpperCamelCase__     : Optional[Any]											=					output_hidden_size or hidden_size
           UpperCamelCase__     : Union[str, Any]											=					adapter_attn_dim

           # SequenceClassification-specific parameter. Feel free to ignore for other classes.
           UpperCamelCase__     : List[str]											=					classifier_proj_size

           # XVector-specific parameters. Feel free to ignore for other classes.
           UpperCamelCase__     : Union[str, Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : Optional[Any]											=					list(__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : int											=					xvector_output_dim






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Optional[Any]:




           """simple docstring"""







           return functools.reduce(operator.mul    ,    self.conv_stride    ,    1	)


