






import functools
import operator

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


snake_case     					=		logging.get_logger(__name__)

snake_case     					=		{
    """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 			SCREAMING_SNAKE_CASE      (      lowerCAmelCase       ):
     '''simple docstring'''


     UpperCamelCase_				:		Union[str, Any]								=						'''unispeech'''


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

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

       # ctc loss
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     ctc_loss_reduction
       SCREAMING_SNAKE_CASE							:   List[Any]						    =     ctc_zero_infinity

       # pretraining loss
       SCREAMING_SNAKE_CASE							:   str						    =     replace_prob






     @property
     def 					_A							(					self							:						int   ):
       return functools.reduce(operator.mul       ,			self.conv_stride       ,			1   )













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,
    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_vision_available, logging


if is_vision_available():
							import PIL


lowerCAmelCase							:       str					 =	logging.get_logger(__name__)





class 				a			(      __lowercase			):
				SCREAMING_SNAKE_CASE__     :   Any		      =     ['''pixel_values''']






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

										"""simple docstring"""




										super().__init__(**_lowerCAmelCase					)
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   size if size is not None else {'''shortest_edge''': 384}
										__SCREAMING_SNAKE_CASE:				List[str]           =   get_size_dict(_lowerCAmelCase			, default_to_square=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   do_resize
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   size
										# Default value set here for backwards compatibility where the value in config is None
										__SCREAMING_SNAKE_CASE:				List[str]           =   crop_pct if crop_pct is not None else 224 / 256
										__SCREAMING_SNAKE_CASE:				List[Any]           =   resample
										__SCREAMING_SNAKE_CASE:				Any           =   do_rescale
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   rescale_factor
										__SCREAMING_SNAKE_CASE:				Any           =   do_normalize
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_std if image_std is not None else IMAGENET_STANDARD_STD






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase = PILImageResampling.BICUBIC			, _lowerCAmelCase = None			, **_lowerCAmelCase			, ):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   get_size_dict(_lowerCAmelCase			, default_to_square=_lowerCAmelCase					)
										if "shortest_edge" not in size:
																raise ValueError(f"""Size dictionary must contain 'shortest_edge' key. Got {size.keys()}"""					)
										__SCREAMING_SNAKE_CASE:				str           =   size['''shortest_edge''']

										if shortest_edge < 384:
																# maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
																__SCREAMING_SNAKE_CASE:				Dict           =   int(shortest_edge / crop_pct					)
																__SCREAMING_SNAKE_CASE:				Any           =   get_resize_output_image_size(_lowerCAmelCase			, size=_lowerCAmelCase			, default_to_square=_lowerCAmelCase					)
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   resize(image=_lowerCAmelCase			, size=_lowerCAmelCase			, resample=_lowerCAmelCase			, data_format=_lowerCAmelCase			, **_lowerCAmelCase					)
																# then crop to (shortest_edge, shortest_edge)
																return center_crop(image=_lowerCAmelCase			, size=(shortest_edge, shortest_edge)			, data_format=_lowerCAmelCase			, **_lowerCAmelCase					)
										else:
																# warping (no cropping) when evaluated at 384 or larger
																return resize(
																    _lowerCAmelCase			, size=(shortest_edge, shortest_edge)			, resample=_lowerCAmelCase			, data_format=_lowerCAmelCase			, **_lowerCAmelCase					)






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase = None			, **_lowerCAmelCase			, ):

										"""simple docstring"""




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






				def 			snake_case_    (  self			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase			, _lowerCAmelCase = None			, **_lowerCAmelCase			, ):

										"""simple docstring"""




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






				def 			snake_case_    (  self			, _lowerCAmelCase			, _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"""




										__SCREAMING_SNAKE_CASE:				List[Any]           =   do_resize if do_resize is not None else self.do_resize
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   crop_pct if crop_pct is not None else self.crop_pct
										__SCREAMING_SNAKE_CASE:				Tuple           =   resample if resample is not None else self.resample
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   do_rescale if do_rescale is not None else self.do_rescale
										__SCREAMING_SNAKE_CASE:				Any           =   rescale_factor if rescale_factor is not None else self.rescale_factor
										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   do_normalize if do_normalize is not None else self.do_normalize
										__SCREAMING_SNAKE_CASE:				Optional[int]           =   image_mean if image_mean is not None else self.image_mean
										__SCREAMING_SNAKE_CASE:				str           =   image_std if image_std is not None else self.image_std

										__SCREAMING_SNAKE_CASE:				List[Any]           =   size if size is not None else self.size
										__SCREAMING_SNAKE_CASE:				Dict           =   get_size_dict(_lowerCAmelCase			, default_to_square=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				List[str]           =   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 or resample is None:
																raise ValueError('''Size and resample must be specified if do_resize is True.'''					)

										if do_resize and size["shortest_edge"] < 384 and crop_pct is None:
																raise ValueError('''crop_pct must be specified if size < 384.'''					)

										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.
										__SCREAMING_SNAKE_CASE:				Tuple           =   [to_numpy_array(_lowerCAmelCase					) for image in images]

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

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

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

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

										__SCREAMING_SNAKE_CASE:				List[str]           =   {'''pixel_values''': images}
										return BatchFeature(data=_lowerCAmelCase			, tensor_type=_lowerCAmelCase					)



