




"""simple docstring"""

from typing import Dict, Iterable, List, Optional, 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_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


a							      =     logging.get_logger(__name__)





class 							lowercase_			(	__lowerCAmelCase				):



 '''simple docstring'''
 UpperCAmelCase       :	Tuple     =      ['''pixel_values''']

 def __init__(					self			:			int       ,				_UpperCAmelCase			:			bool = True       ,				_UpperCAmelCase			:			Dict[str, int] = None       ,				_UpperCAmelCase			:			PILImageResampling = PILImageResampling.BICUBIC       ,				_UpperCAmelCase			:			bool = True       ,				_UpperCAmelCase			:			Dict[str, int] = None       ,				_UpperCAmelCase			:			bool = True       ,				_UpperCAmelCase			:			Union[int, float] = 1 / 255       ,				_UpperCAmelCase			:			bool = True       ,				_UpperCAmelCase			:			Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_MEAN       ,				_UpperCAmelCase			:			Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_STD       ,				**_UpperCAmelCase			:			Any       ,				):
       super().__init__(**_UpperCAmelCase						)
       _A     =  size if size is not None else {'shortest_edge': 224}
       _A     =  get_size_dict(_UpperCAmelCase       ,				default_to_square=_UpperCAmelCase						)
       _A     =  crop_size if crop_size is not None else {'height': 224, 'width': 224}
       _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_DEFAULT_MEAN
       _A     =  image_std if image_std is not None else IMAGENET_DEFAULT_STD

 def      lowerCAmelCase_				(					self			:			Dict       ,				_UpperCAmelCase			:			np.ndarray       ,				_UpperCAmelCase			:			Dict[str, int]       ,				_UpperCAmelCase			:			PILImageResampling = PILImageResampling.BICUBIC       ,				_UpperCAmelCase			:			Optional[Union[str, ChannelDimension]] = None       ,				**_UpperCAmelCase			:			Dict       ,				):
       _A     =  get_size_dict(_UpperCAmelCase       ,				default_to_square=_UpperCAmelCase						)
       # size_dict is a dict with either keys "height" and "width" or "shortest_edge"
       if "shortest_edge" in size:
             _A     =  int((256 / 224) * size['shortest_edge']						)
             _A     =  get_resize_output_image_size(_UpperCAmelCase       ,				size=_UpperCAmelCase       ,				default_to_square=_UpperCAmelCase						)
             _A     =  {'height': output_size[0], 'width': output_size[1]}
       if "height" not in size_dict or "width" not in size_dict:
             raise ValueError(
                 F'''Size dict must have keys \'height\' and \'width\' or \'shortest_edge\'. Got {size_dict.keys()}'''						)
       return resize(
           _UpperCAmelCase       ,				size=(size_dict['height'], size_dict['width'])       ,				resample=_UpperCAmelCase       ,				data_format=_UpperCAmelCase       ,				**_UpperCAmelCase						)

 def      lowerCAmelCase_				(					self			:			Dict       ,				_UpperCAmelCase			:			np.ndarray       ,				_UpperCAmelCase			:			Dict[str, int]       ,				_UpperCAmelCase			:			Optional[Union[str, ChannelDimension]] = None       ,				**_UpperCAmelCase			:			Optional[Any]       ,				):
       _A     =  get_size_dict(_UpperCAmelCase						)
       if "height" not in size or "width" not in size:
             raise ValueError(F'''Size dict must have keys \'height\' and \'width\'. Got {size.keys()}'''						)
       return center_crop(_UpperCAmelCase       ,				size=(size['height'], size['width'])       ,				data_format=_UpperCAmelCase       ,				**_UpperCAmelCase						)

 def      lowerCAmelCase_				(					self			:			Dict       ,				_UpperCAmelCase			:			np.ndarray       ,				_UpperCAmelCase			:			Union[int, float]       ,				_UpperCAmelCase			:			Optional[Union[str, ChannelDimension]] = None       ,				**_UpperCAmelCase			:			Optional[int]       ,				):
       return rescale(_UpperCAmelCase       ,				scale=_UpperCAmelCase       ,				data_format=_UpperCAmelCase       ,				**_UpperCAmelCase						)

 def      lowerCAmelCase_				(					self			:			str       ,				_UpperCAmelCase			:			np.ndarray       ,				_UpperCAmelCase			:			Union[float, List[float]]       ,				_UpperCAmelCase			:			Union[float, List[float]]       ,				_UpperCAmelCase			:			Optional[Union[str, ChannelDimension]] = None       ,				**_UpperCAmelCase			:			int       ,				):
       return normalize(_UpperCAmelCase       ,				mean=_UpperCAmelCase       ,				std=_UpperCAmelCase       ,				data_format=_UpperCAmelCase       ,				**_UpperCAmelCase						)



 def      lowerCAmelCase_				(					self			:			Tuple       ,				_UpperCAmelCase			:			ImageInput       ,				_UpperCAmelCase			:			Optional[bool] = None       ,				_UpperCAmelCase			:			Optional[Dict[str, int]] = None       ,				_UpperCAmelCase			:			PILImageResampling = None       ,				_UpperCAmelCase			:			Optional[bool] = None       ,				_UpperCAmelCase			:			Optional[Dict[str, int]] = None       ,				_UpperCAmelCase			:			Optional[bool] = None       ,				_UpperCAmelCase			:			Optional[float] = None       ,				_UpperCAmelCase			:			Optional[bool] = None       ,				_UpperCAmelCase			:			Optional[Union[float, Iterable[float]]] = None       ,				_UpperCAmelCase			:			Optional[Union[float, Iterable[float]]] = None       ,				_UpperCAmelCase			:			Optional[TensorType] = None       ,				_UpperCAmelCase			:			ChannelDimension = ChannelDimension.FIRST       ,				**_UpperCAmelCase			:			Dict       ,				):
       _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_center_crop if do_center_crop is not None else self.do_center_crop
       _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     =  size if size is not None else self.size
       _A     =  get_size_dict(_UpperCAmelCase       ,				default_to_square=_UpperCAmelCase						)
       _A     =  crop_size if crop_size is not None else self.crop_size
       _A     =  get_size_dict(_UpperCAmelCase       ,				param_name='crop_size'						)

       _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(_UpperCAmelCase       ,				_UpperCAmelCase       ,				_UpperCAmelCase						) for image in images]

       if do_center_crop:
             _A     =  [self.center_crop(_UpperCAmelCase       ,				_UpperCAmelCase						) for image in images]

       if do_rescale:
             _A     =  [self.rescale(_UpperCAmelCase       ,				_UpperCAmelCase						) for image in images]

       if do_normalize:
             _A     =  [self.normalize(_UpperCAmelCase       ,				_UpperCAmelCase       ,				_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						)







import functools
import operator

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


__a							     =					logging.get_logger(__name__)

__a							     =					{
    '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     __a(	_a  ):






    """simple docstring"""





    lowerCAmelCase         = '''wav2vec2'''





    def __init__( self  ,_SCREAMING_SNAKE_CASE=32  ,_SCREAMING_SNAKE_CASE=768  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=12  ,_SCREAMING_SNAKE_CASE=3_072  ,_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=(512, 512, 512, 512, 512, 512, 512)  ,_SCREAMING_SNAKE_CASE=(5, 2, 2, 2, 2, 2, 2)  ,_SCREAMING_SNAKE_CASE=(10, 3, 3, 3, 3, 2, 2)  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=128  ,_SCREAMING_SNAKE_CASE=16  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=True  ,_SCREAMING_SNAKE_CASE=0.05  ,_SCREAMING_SNAKE_CASE=10  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=0.0  ,_SCREAMING_SNAKE_CASE=10  ,_SCREAMING_SNAKE_CASE=0  ,_SCREAMING_SNAKE_CASE=320  ,_SCREAMING_SNAKE_CASE=2  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE=100  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=0.1  ,_SCREAMING_SNAKE_CASE="sum"  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=False  ,_SCREAMING_SNAKE_CASE=256  ,_SCREAMING_SNAKE_CASE=(512, 512, 512, 512, 1_500)  ,_SCREAMING_SNAKE_CASE=(5, 3, 3, 1, 1)  ,_SCREAMING_SNAKE_CASE=(1, 2, 3, 1, 1)  ,_SCREAMING_SNAKE_CASE=512  ,_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  ,)					->						Optional[int]:
         super().__init__(**_SCREAMING_SNAKE_CASE  ,pad_token_id=_SCREAMING_SNAKE_CASE  ,bos_token_id=_SCREAMING_SNAKE_CASE  ,eos_token_id=_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				int  =     hidden_size
         UpperCAmelCase_     :				Tuple  =     feat_extract_norm
         UpperCAmelCase_     :				List[Any]  =     feat_extract_activation
         UpperCAmelCase_     :				str  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Any  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Tuple  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Dict  =     conv_bias
         UpperCAmelCase_     :				str  =     num_conv_pos_embeddings
         UpperCAmelCase_     :				Any  =     num_conv_pos_embedding_groups
         UpperCAmelCase_     :				Tuple  =     len(self.conv_dim    )
         UpperCAmelCase_     :				Union[str, Any]  =     num_hidden_layers
         UpperCAmelCase_     :				Dict  =     intermediate_size
         UpperCAmelCase_     :				Any  =     hidden_act
         UpperCAmelCase_     :				Any  =     num_attention_heads
         UpperCAmelCase_     :				str  =     hidden_dropout
         UpperCAmelCase_     :				int  =     attention_dropout
         UpperCAmelCase_     :				Tuple  =     activation_dropout
         UpperCAmelCase_     :				List[str]  =     feat_proj_dropout
         UpperCAmelCase_     :				int  =     final_dropout
         UpperCAmelCase_     :				Union[str, Any]  =     layerdrop
         UpperCAmelCase_     :				Optional[Any]  =     layer_norm_eps
         UpperCAmelCase_     :				str  =     initializer_range
         UpperCAmelCase_     :				List[str]  =     vocab_size
         UpperCAmelCase_     :				Optional[int]  =     do_stable_layer_norm
         UpperCAmelCase_     :				Optional[int]  =     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_     :				Optional[int]  =     apply_spec_augment
         UpperCAmelCase_     :				Tuple  =     mask_time_prob
         UpperCAmelCase_     :				Optional[Any]  =     mask_time_length
         UpperCAmelCase_     :				Union[str, Any]  =     mask_time_min_masks
         UpperCAmelCase_     :				Optional[Any]  =     mask_feature_prob
         UpperCAmelCase_     :				str  =     mask_feature_length
         UpperCAmelCase_     :				Dict  =     mask_feature_min_masks

         # parameters for pretraining with codevector quantized representations
         UpperCAmelCase_     :				Union[str, Any]  =     num_codevectors_per_group
         UpperCAmelCase_     :				Any  =     num_codevector_groups
         UpperCAmelCase_     :				Union[str, Any]  =     contrastive_logits_temperature
         UpperCAmelCase_     :				List[str]  =     feat_quantizer_dropout
         UpperCAmelCase_     :				Dict  =     num_negatives
         UpperCAmelCase_     :				List[str]  =     codevector_dim
         UpperCAmelCase_     :				List[str]  =     proj_codevector_dim
         UpperCAmelCase_     :				str  =     diversity_loss_weight

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

         # adapter
         UpperCAmelCase_     :				Optional[Any]  =     add_adapter
         UpperCAmelCase_     :				Any  =     adapter_kernel_size
         UpperCAmelCase_     :				Optional[int]  =     adapter_stride
         UpperCAmelCase_     :				List[Any]  =     num_adapter_layers
         UpperCAmelCase_     :				Optional[Any]  =     output_hidden_size or hidden_size
         UpperCAmelCase_     :				Optional[int]  =     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_     :				List[str]  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				int  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Dict  =     list(_SCREAMING_SNAKE_CASE    )
         UpperCAmelCase_     :				Any  =     xvector_output_dim





    @property
    def 				a__ ( self    )					->						Any:
         return functools.reduce(operator.mul  ,self.conv_stride  ,1    )