




'''simple docstring'''



import functools
import operator

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


lowerCamelCase_									=		logging.get_logger(__name__)

lowerCamelCase_									=		{
    'microsoft/unispeech-large-1500h-cv': (
        'https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}







class 						lowercase_       (					SCREAMING_SNAKE_CASE__  ):


   """simple docstring"""

   lowerCamelCase_							    =		'''unispeech'''



   def __init__(       self   :      List[str]    , __lowerCamelCase   :      Dict=3_2    , __lowerCamelCase   :      Optional[int]=7_6_8    , __lowerCamelCase   :      Dict=1_2    , __lowerCamelCase   :      List[str]=1_2    , __lowerCamelCase   :      List[Any]=3_0_7_2    , __lowerCamelCase   :      Any="gelu"    , __lowerCamelCase   :      Optional[int]=0.1    , __lowerCamelCase   :      Optional[int]=0.1    , __lowerCamelCase   :      Optional[int]=0.1    , __lowerCamelCase   :      Dict=0.0    , __lowerCamelCase   :      Dict=0.0    , __lowerCamelCase   :      int=0.1    , __lowerCamelCase   :      Optional[Any]=0.1    , __lowerCamelCase   :      int=0.0_2    , __lowerCamelCase   :      Dict=1e-5    , __lowerCamelCase   :      Optional[int]="group"    , __lowerCamelCase   :      Tuple="gelu"    , __lowerCamelCase   :      Optional[int]=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)    , __lowerCamelCase   :      Tuple=(5, 2, 2, 2, 2, 2, 2)    , __lowerCamelCase   :      Tuple=(1_0, 3, 3, 3, 3, 2, 2)    , __lowerCamelCase   :      List[Any]=False    , __lowerCamelCase   :      Dict=1_2_8    , __lowerCamelCase   :      str=1_6    , __lowerCamelCase   :      List[Any]=False    , __lowerCamelCase   :      Dict=True    , __lowerCamelCase   :      Optional[Any]=0.0_5    , __lowerCamelCase   :      List[Any]=1_0    , __lowerCamelCase   :      Optional[int]=2    , __lowerCamelCase   :      List[Any]=0.0    , __lowerCamelCase   :      Tuple=1_0    , __lowerCamelCase   :      Optional[int]=0    , __lowerCamelCase   :      Optional[Any]=3_2_0    , __lowerCamelCase   :      str=2    , __lowerCamelCase   :      List[str]=0.1    , __lowerCamelCase   :      List[str]=1_0_0    , __lowerCamelCase   :      Tuple=2_5_6    , __lowerCamelCase   :      str=2_5_6    , __lowerCamelCase   :      str=0.1    , __lowerCamelCase   :      Dict="mean"    , __lowerCamelCase   :      Optional[Any]=False    , __lowerCamelCase   :      Optional[int]=False    , __lowerCamelCase   :      Optional[Any]=2_5_6    , __lowerCamelCase   :      str=8_0    , __lowerCamelCase   :      int=0    , __lowerCamelCase   :      int=1    , __lowerCamelCase   :      Dict=2    , __lowerCamelCase   :      List[Any]=0.5    , **__lowerCamelCase   :      Dict    , ):

      """simple docstring"""
      super().__init__(**__lowerCamelCase    , pad_token_id=__lowerCamelCase    , bos_token_id=__lowerCamelCase    , eos_token_id=__lowerCamelCase       )
      _SCREAMING_SNAKE_CASE			= hidden_size
      _SCREAMING_SNAKE_CASE			= feat_extract_norm
      _SCREAMING_SNAKE_CASE			= feat_extract_activation
      _SCREAMING_SNAKE_CASE			= list(__lowerCamelCase       )
      _SCREAMING_SNAKE_CASE			= list(__lowerCamelCase       )
      _SCREAMING_SNAKE_CASE			= list(__lowerCamelCase       )
      _SCREAMING_SNAKE_CASE			= conv_bias
      _SCREAMING_SNAKE_CASE			= num_conv_pos_embeddings
      _SCREAMING_SNAKE_CASE			= num_conv_pos_embedding_groups
      _SCREAMING_SNAKE_CASE			= len(self.conv_dim       )
      _SCREAMING_SNAKE_CASE			= num_hidden_layers
      _SCREAMING_SNAKE_CASE			= intermediate_size
      _SCREAMING_SNAKE_CASE			= hidden_act
      _SCREAMING_SNAKE_CASE			= num_attention_heads
      _SCREAMING_SNAKE_CASE			= hidden_dropout
      _SCREAMING_SNAKE_CASE			= attention_dropout
      _SCREAMING_SNAKE_CASE			= activation_dropout
      _SCREAMING_SNAKE_CASE			= feat_proj_dropout
      _SCREAMING_SNAKE_CASE			= final_dropout
      _SCREAMING_SNAKE_CASE			= layerdrop
      _SCREAMING_SNAKE_CASE			= layer_norm_eps
      _SCREAMING_SNAKE_CASE			= initializer_range
      _SCREAMING_SNAKE_CASE			= num_ctc_classes
      _SCREAMING_SNAKE_CASE			= vocab_size
      _SCREAMING_SNAKE_CASE			= do_stable_layer_norm
      _SCREAMING_SNAKE_CASE			= use_weighted_layer_sum
      _SCREAMING_SNAKE_CASE			= classifier_proj_size

      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
      _SCREAMING_SNAKE_CASE			= apply_spec_augment
      _SCREAMING_SNAKE_CASE			= mask_time_prob
      _SCREAMING_SNAKE_CASE			= mask_time_length
      _SCREAMING_SNAKE_CASE			= mask_time_min_masks
      _SCREAMING_SNAKE_CASE			= mask_feature_prob
      _SCREAMING_SNAKE_CASE			= mask_feature_length
      _SCREAMING_SNAKE_CASE			= mask_feature_min_masks

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

      # ctc loss
      _SCREAMING_SNAKE_CASE			= ctc_loss_reduction
      _SCREAMING_SNAKE_CASE			= ctc_zero_infinity

      # pretraining loss
      _SCREAMING_SNAKE_CASE			= replace_prob



   @property
   def 				lowerCAmelCase_     (       self   :      int       ):

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








"""simple docstring"""



from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


a_					=     logging.get_logger(__name__)


if is_vision_available():
       import PIL






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	["""pixel_values"""]

 def __init__(       self   ,		__lowerCamelCase = True   ,		__lowerCamelCase = None   ,		__lowerCamelCase = PILImageResampling.BICUBIC   ,		__lowerCamelCase = True   ,		__lowerCamelCase = None   ,		__lowerCamelCase = True   ,		__lowerCamelCase = 1 / 255   ,		__lowerCamelCase = True   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = True   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase    )
     __A       :		Optional[int]							=	size if size is not None else {'''shortest_edge''': 224}
     __A       :		Optional[int]							=	get_size_dict(__lowerCamelCase   ,		default_to_square=__lowerCamelCase    )
     __A       :		Dict							=	crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
     __A       :		str							=	get_size_dict(__lowerCamelCase   ,		default_to_square=__lowerCamelCase   ,		param_name='''crop_size'''    )

     __A       :		Dict							=	do_resize
     __A       :		Optional[Any]							=	size
     __A       :		Optional[Any]							=	resample
     __A       :		Dict							=	do_center_crop
     __A       :		Any							=	crop_size
     __A       :		Optional[Any]							=	do_rescale
     __A       :		List[Any]							=	rescale_factor
     __A       :		Union[str, Any]							=	do_normalize
     __A       :		Any							=	image_mean if image_mean is not None else OPENAI_CLIP_MEAN
     __A       :		Optional[int]							=	image_std if image_std is not None else OPENAI_CLIP_STD
     __A       :		Dict							=	do_convert_rgb

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase = PILImageResampling.BICUBIC   ,		__lowerCamelCase = None   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     __A       :		Optional[Any]							=	get_size_dict(__lowerCamelCase   ,		default_to_square=__lowerCamelCase    )
     if "shortest_edge" not in size:
         raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""    )
     __A       :		Optional[int]							=	get_resize_output_image_size(__lowerCamelCase   ,		size=size['''shortest_edge''']   ,		default_to_square=__lowerCamelCase    )
     return resize(__lowerCamelCase   ,		size=__lowerCamelCase   ,		resample=__lowerCamelCase   ,		data_format=__lowerCamelCase   ,		**__lowerCamelCase    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase = None   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     __A       :		Optional[Any]							=	get_size_dict(__lowerCamelCase    )
     if "height" not in size or "width" not in size:
         raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""    )
     return center_crop(__lowerCamelCase   ,		size=(size['''height'''], size['''width'''])   ,		data_format=__lowerCamelCase   ,		**__lowerCamelCase    )

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase = None   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




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

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase = None   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




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







 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = None   ,		__lowerCamelCase = ChannelDimension.FIRST   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     __A       :		Tuple							=	do_resize if do_resize is not None else self.do_resize
     __A       :		Any							=	size if size is not None else self.size
     __A       :		List[str]							=	get_size_dict(__lowerCamelCase   ,		param_name='''size'''   ,		default_to_square=__lowerCamelCase    )
     __A       :		List[Any]							=	resample if resample is not None else self.resample
     __A       :		Any							=	do_center_crop if do_center_crop is not None else self.do_center_crop
     __A       :		Dict							=	crop_size if crop_size is not None else self.crop_size
     __A       :		List[Any]							=	get_size_dict(__lowerCamelCase   ,		param_name='''crop_size'''   ,		default_to_square=__lowerCamelCase    )
     __A       :		List[str]							=	do_rescale if do_rescale is not None else self.do_rescale
     __A       :		List[Any]							=	rescale_factor if rescale_factor is not None else self.rescale_factor
     __A       :		Tuple							=	do_normalize if do_normalize is not None else self.do_normalize
     __A       :		str							=	image_mean if image_mean is not None else self.image_mean
     __A       :		int							=	image_std if image_std is not None else self.image_std
     __A       :		Union[str, Any]							=	do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

     __A       :		int							=	make_list_of_images(__lowerCamelCase    )

     if not valid_images(__lowerCamelCase    ):
         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.'''    )

     # PIL RGBA images are converted to RGB
     if do_convert_rgb:
         __A       :		List[str]							=	[convert_to_rgb(__lowerCamelCase    ) for image in images]

     # All transformations expect numpy arrays.
     __A       :		Optional[int]							=	[to_numpy_array(__lowerCamelCase    ) for image in images]

     if do_resize:
         __A       :		List[str]							=	[self.resize(image=__lowerCamelCase   ,		size=__lowerCamelCase   ,		resample=__lowerCamelCase    ) for image in images]

     if do_center_crop:
         __A       :		Dict							=	[self.center_crop(image=__lowerCamelCase   ,		size=__lowerCamelCase    ) for image in images]

     if do_rescale:
         __A       :		str							=	[self.rescale(image=__lowerCamelCase   ,		scale=__lowerCamelCase    ) for image in images]

     if do_normalize:
         __A       :		Optional[Any]							=	[self.normalize(image=__lowerCamelCase   ,		mean=__lowerCamelCase   ,		std=__lowerCamelCase    ) for image in images]

     __A       :		str							=	[to_channel_dimension_format(__lowerCamelCase   ,		__lowerCamelCase    ) for image in images]

     __A       :		Union[str, Any]							=	{'''pixel_values''': images}
     return BatchFeature(data=__lowerCamelCase   ,		tensor_type=__lowerCamelCase    )




