
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	)




from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowerCamelCase  =logging.get_logger(__name__)




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	['''pixel_values''']






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE = True    ,    __SCREAMING_SNAKE_CASE = 3_2    ,    __SCREAMING_SNAKE_CASE=PILImageResampling.BILINEAR    ,    __SCREAMING_SNAKE_CASE = True    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> None:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					do_resize
           UpperCamelCase__     : Tuple											=					do_rescale
           UpperCamelCase__     : Dict											=					size_divisor
           UpperCamelCase__     : str											=					resample
           super().__init__(**__SCREAMING_SNAKE_CASE	)






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = None    ,    **__SCREAMING_SNAKE_CASE	)	-> np.ndarray:




           """simple docstring"""







           UpperCamelCase__					,UpperCamelCase__     : Optional[Any]											=					get_image_size(__SCREAMING_SNAKE_CASE	)
           # Rounds the height and width down to the closest multiple of size_divisor
           UpperCamelCase__     : List[Any]											=					height // size_divisor * size_divisor
           UpperCamelCase__     : Dict											=					width // size_divisor * size_divisor
           UpperCamelCase__     : str											=					resize(__SCREAMING_SNAKE_CASE    ,    (new_h, new_w)    ,    resample=__SCREAMING_SNAKE_CASE    ,    data_format=__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)
           return image






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = None    ,    **__SCREAMING_SNAKE_CASE	)	-> np.ndarray:




           """simple docstring"""







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






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = ChannelDimension.FIRST    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> BatchFeature:




           """simple docstring"""







           UpperCamelCase__     : Dict											=					do_resize if do_resize is not None else self.do_resize
           UpperCamelCase__     : List[Any]											=					do_rescale if do_rescale is not None else self.do_rescale
           UpperCamelCase__     : Union[str, Any]											=					size_divisor if size_divisor is not None else self.size_divisor
           UpperCamelCase__     : List[str]											=					resample if resample is not None else self.resample

           if do_resize and size_divisor is None:
                 raise ValueError('''size_divisor is required for resizing'''	)

           UpperCamelCase__     : List[Any]											=					make_list_of_images(__SCREAMING_SNAKE_CASE	)

           if not valid_images(__SCREAMING_SNAKE_CASE	):
                 raise ValueError('''Invalid image(s)'''	)

           # All transformations expect numpy arrays.
           UpperCamelCase__     : Dict											=					[to_numpy_array(__SCREAMING_SNAKE_CASE	) for img in images]

           if do_resize:
                 UpperCamelCase__     : Optional[int]											=					[self.resize(__SCREAMING_SNAKE_CASE    ,    size_divisor=__SCREAMING_SNAKE_CASE    ,    resample=__SCREAMING_SNAKE_CASE	) for image in images]

           if do_rescale:
                 UpperCamelCase__     : Union[str, Any]											=					[self.rescale(__SCREAMING_SNAKE_CASE    ,    scale=1 / 2_5_5	) for image in images]

           UpperCamelCase__     : List[str]											=					[to_channel_dimension_format(__SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE	) for image in images]

           UpperCamelCase__     : Optional[Any]											=					{'''pixel_values''': images}
           return BatchFeature(data=__SCREAMING_SNAKE_CASE    ,    tensor_type=__SCREAMING_SNAKE_CASE	)


