




"""simple docstring"""



import functools
import operator

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


__lowercase		:		Any														=							logging.get_logger(__name__)

__lowercase		:		List[Any]														=							{
    "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	(						_UpperCAmelCase					):




    """simple docstring"""




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

         # parameters for pretraining with codevector quantized representations
         __snake_case				=							num_codevectors_per_group
         __snake_case				=							num_codevector_groups
         __snake_case				=							contrastive_logits_temperature
         __snake_case				=							feat_quantizer_dropout
         __snake_case				=							num_negatives
         __snake_case				=							codevector_dim
         __snake_case				=							proj_codevector_dim
         __snake_case				=							diversity_loss_weight

         # ctc loss
         __snake_case				=							ctc_loss_reduction
         __snake_case				=							ctc_zero_infinity

         # adapter
         __snake_case				=							add_adapter
         __snake_case				=							adapter_kernel_size
         __snake_case				=							adapter_stride
         __snake_case				=							num_adapter_layers
         __snake_case				=							output_hidden_size or hidden_size
         __snake_case				=							adapter_attn_dim

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         __snake_case				=							classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         __snake_case				=							list(A_    )
         __snake_case				=							list(A_    )
         __snake_case				=							list(A_    )
         __snake_case				=							xvector_output_dim







    @property
    def  lowercase					(		self							:     Optional[Any]    )    ->       str:
         return functools.reduce(operator.mul	,      self.conv_stride	,      1    )
"""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


__lowercase		:		str														=							logging.get_logger(__name__)



class      _A	(						_UpperCAmelCase					):




    """simple docstring"""




    UpperCamelCase_	:					str							=					['''pixel_values''']
    def __init__(		self							:     Optional[int]	,      A_							:     bool = True	,      A_							:     Dict[str, int] = None	,      A_							:     PILImageResampling = PILImageResampling.BICUBIC	,      A_							:     bool = True	,      A_							:     Dict[str, int] = None	,      A_							:     bool = True	,      A_							:     Union[int, float] = 1 / 255	,      A_							:     bool = True	,      A_							:     Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_MEAN	,      A_							:     Optional[Union[float, Iterable[float]]] = IMAGENET_DEFAULT_STD	,      **A_							:     Dict	,      )    ->       None:
         super().__init__(**A_    )
         __snake_case				=							size if size is not None else {'''shortest_edge''': 224}
         __snake_case				=							get_size_dict(A_	,      default_to_square=A_    )
         __snake_case				=							crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
         __snake_case				=							get_size_dict(A_	,      param_name='''crop_size'''    )

         __snake_case				=							do_resize
         __snake_case				=							size
         __snake_case				=							resample
         __snake_case				=							do_center_crop
         __snake_case				=							crop_size
         __snake_case				=							do_rescale
         __snake_case				=							rescale_factor
         __snake_case				=							do_normalize
         __snake_case				=							image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
         __snake_case				=							image_std if image_std is not None else IMAGENET_DEFAULT_STD
    def  lowercase					(		self							:     Any	,      A_							:     np.ndarray	,      A_							:     Dict[str, int]	,      A_							:     PILImageResampling = PILImageResampling.BICUBIC	,      A_							:     Optional[Union[str, ChannelDimension]] = None	,      **A_							:     int	,      )    ->       np.ndarray:
         __snake_case				=							get_size_dict(A_	,      default_to_square=A_    )
         # size_dict is a dict with either keys "height" and "width" or "shortest_edge"
         if "shortest_edge" in size:
              __snake_case				=							int((256 / 224) * size['''shortest_edge''']    )
              __snake_case				=							get_resize_output_image_size(A_	,      size=A_	,      default_to_square=A_    )
              __snake_case				=							{'''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(
             A_	,      size=(size_dict['''height'''], size_dict['''width'''])	,      resample=A_	,      data_format=A_	,      **A_    )
    def  lowercase					(		self							:     Any	,      A_							:     np.ndarray	,      A_							:     Dict[str, int]	,      A_							:     Optional[Union[str, ChannelDimension]] = None	,      **A_							:     List[Any]	,      )    ->       np.ndarray:
         __snake_case				=							get_size_dict(A_    )
         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(A_	,      size=(size['''height'''], size['''width'''])	,      data_format=A_	,      **A_    )
    def  lowercase					(		self							:     List[str]	,      A_							:     np.ndarray	,      A_							:     Union[int, float]	,      A_							:     Optional[Union[str, ChannelDimension]] = None	,      **A_							:     Optional[Any]	,      )    ->       np.ndarray:
         return rescale(A_	,      scale=A_	,      data_format=A_	,      **A_    )
    def  lowercase					(		self							:     Dict	,      A_							:     np.ndarray	,      A_							:     Union[float, List[float]]	,      A_							:     Union[float, List[float]]	,      A_							:     Optional[Union[str, ChannelDimension]] = None	,      **A_							:     Optional[int]	,      )    ->       np.ndarray:
         return normalize(A_	,      mean=A_	,      std=A_	,      data_format=A_	,      **A_    )







    def  lowercase					(		self							:     Union[str, Any]	,      A_							:     ImageInput	,      A_							:     Optional[bool] = None	,      A_							:     Optional[Dict[str, int]] = None	,      A_							:     PILImageResampling = None	,      A_							:     Optional[bool] = None	,      A_							:     Optional[Dict[str, int]] = None	,      A_							:     Optional[bool] = None	,      A_							:     Optional[float] = None	,      A_							:     Optional[bool] = None	,      A_							:     Optional[Union[float, Iterable[float]]] = None	,      A_							:     Optional[Union[float, Iterable[float]]] = None	,      A_							:     Optional[TensorType] = None	,      A_							:     ChannelDimension = ChannelDimension.FIRST	,      **A_							:     Any	,      )    ->       BatchFeature:
         __snake_case				=							do_resize if do_resize is not None else self.do_resize
         __snake_case				=							resample if resample is not None else self.resample
         __snake_case				=							do_center_crop if do_center_crop is not None else self.do_center_crop
         __snake_case				=							do_rescale if do_rescale is not None else self.do_rescale
         __snake_case				=							rescale_factor if rescale_factor is not None else self.rescale_factor
         __snake_case				=							do_normalize if do_normalize is not None else self.do_normalize
         __snake_case				=							image_mean if image_mean is not None else self.image_mean
         __snake_case				=							image_std if image_std is not None else self.image_std

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

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

         if do_resize:
              __snake_case				=							[self.resize(A_	,      A_	,      A_    ) for image in images]

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

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

         if do_normalize:
              __snake_case				=							[self.normalize(A_	,      A_	,      A_    ) for image in images]

         __snake_case				=							[to_channel_dimension_format(A_	,      A_    ) for image in images]

         __snake_case				=							{'''pixel_values''': images}
         return BatchFeature(data=A_	,      tensor_type=A_    )