

"""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,
    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,
    is_batched,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


A_							:			Union[str, Any]											= logging.get_logger(__name__)





class    lowerCamelCase						(A__			):
			lowerCamelCase__   :		List[Any]							=							['pixel_values']

			def __init__(					self				:						List[Any]    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Optional[Dict[str, int]] = None    ,				__UpperCAmelCase				:						PILImageResampling = PILImageResampling.BICUBIC    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Union[int, float] = 1 / 2_5_5    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						bool = True    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				**__UpperCAmelCase				:						str    ,				)   ->    None:
						super().__init__(**__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      size if size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				default_to_square=__UpperCAmelCase    ,				param_name="""crop_size"""       )

						SCREAMING_SNAKE_CASE__								=      do_resize
						SCREAMING_SNAKE_CASE__								=      do_rescale
						SCREAMING_SNAKE_CASE__								=      do_normalize
						SCREAMING_SNAKE_CASE__								=      do_center_crop
						SCREAMING_SNAKE_CASE__								=      crop_size
						SCREAMING_SNAKE_CASE__								=      size
						SCREAMING_SNAKE_CASE__								=      resample
						SCREAMING_SNAKE_CASE__								=      rescale_factor
						SCREAMING_SNAKE_CASE__								=      image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
						SCREAMING_SNAKE_CASE__								=      image_std if image_std is not None else IMAGENET_DEFAULT_STD

			def 					SCREAMING_SNAKE_CASE				(					self				:						Tuple    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Dict[str, int]    ,				__UpperCAmelCase				:						PILImageResampling = PILImageResampling.BILINEAR    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						List[Any]    ,				)   ->    np.ndarray:
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase       )

						if "shortest_edge" in size:
									SCREAMING_SNAKE_CASE__								=      get_resize_output_image_size(__UpperCAmelCase    ,				size=size["""shortest_edge"""]    ,				default_to_square=__UpperCAmelCase       )
									# size = get_resize_output_image_size(image, size["shortest_edge"], size["longest_edge"])
						elif "height" in size and "width" in size:
									SCREAMING_SNAKE_CASE__								=      (size["""height"""], size["""width"""])
						else:
									raise ValueError(F"""Size must contain 'height' and 'width' keys or 'shortest_edge' key. Got {size.keys()}"""       )
						return resize(__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						Dict    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Dict[str, int]    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						Optional[Any]    ,				)   ->    np.ndarray:
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase       )
						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(__UpperCAmelCase    ,				size=(size["""height"""], size["""width"""])    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						Union[str, Any]    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						float    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						Union[str, Any]       )   ->    np.ndarray:
						return rescale(__UpperCAmelCase    ,				scale=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )

			def 					SCREAMING_SNAKE_CASE				(					self				:						Union[str, Any]    ,				__UpperCAmelCase				:						np.ndarray    ,				__UpperCAmelCase				:						Union[float, List[float]]    ,				__UpperCAmelCase				:						Union[float, List[float]]    ,				__UpperCAmelCase				:						Optional[Union[str, ChannelDimension]] = None    ,				**__UpperCAmelCase				:						List[str]    ,				)   ->    np.ndarray:
						return normalize(__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase    ,				data_format=__UpperCAmelCase    ,				**__UpperCAmelCase       )





			def 					SCREAMING_SNAKE_CASE				(					self				:						List[str]    ,				__UpperCAmelCase				:						ImageInput    ,				__UpperCAmelCase				:						Optional[bool] = None    ,				__UpperCAmelCase				:						Dict[str, int] = None    ,				__UpperCAmelCase				:						PILImageResampling = None    ,				__UpperCAmelCase				:						bool = None    ,				__UpperCAmelCase				:						int = None    ,				__UpperCAmelCase				:						Optional[bool] = None    ,				__UpperCAmelCase				:						Optional[float] = None    ,				__UpperCAmelCase				:						Optional[bool] = None    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				__UpperCAmelCase				:						Optional[Union[float, List[float]]] = None    ,				__UpperCAmelCase				:						Optional[Union[str, TensorType]] = None    ,				__UpperCAmelCase				:						Union[str, ChannelDimension] = ChannelDimension.FIRST    ,				**__UpperCAmelCase				:						Any    ,				)   ->    BatchFeature:
						SCREAMING_SNAKE_CASE__								=      do_resize if do_resize is not None else self.do_resize
						SCREAMING_SNAKE_CASE__								=      do_rescale if do_rescale is not None else self.do_rescale
						SCREAMING_SNAKE_CASE__								=      do_normalize if do_normalize is not None else self.do_normalize
						SCREAMING_SNAKE_CASE__								=      do_center_crop if do_center_crop is not None else self.do_center_crop
						SCREAMING_SNAKE_CASE__								=      crop_size if crop_size is not None else self.crop_size
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase    ,				param_name="""crop_size"""    ,				default_to_square=__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      resample if resample is not None else self.resample
						SCREAMING_SNAKE_CASE__								=      rescale_factor if rescale_factor is not None else self.rescale_factor
						SCREAMING_SNAKE_CASE__								=      image_mean if image_mean is not None else self.image_mean
						SCREAMING_SNAKE_CASE__								=      image_std if image_std is not None else self.image_std

						SCREAMING_SNAKE_CASE__								=      size if size is not None else self.size
						SCREAMING_SNAKE_CASE__								=      get_size_dict(__UpperCAmelCase       )

						if not is_batched(__UpperCAmelCase       ):
									SCREAMING_SNAKE_CASE__								=      [images]

						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."""       )

						# All transformations expect numpy arrays.
						SCREAMING_SNAKE_CASE__								=      [to_numpy_array(__UpperCAmelCase       ) for image in images]

						if do_resize:
									SCREAMING_SNAKE_CASE__								=      [self.resize(image=__UpperCAmelCase    ,				size=__UpperCAmelCase    ,				resample=__UpperCAmelCase       ) for image in images]

						if do_center_crop:
									SCREAMING_SNAKE_CASE__								=      [self.center_crop(image=__UpperCAmelCase    ,				size=__UpperCAmelCase       ) for image in images]

						if do_rescale:
									SCREAMING_SNAKE_CASE__								=      [self.rescale(image=__UpperCAmelCase    ,				scale=__UpperCAmelCase       ) for image in images]

						if do_normalize:
									SCREAMING_SNAKE_CASE__								=      [self.normalize(image=__UpperCAmelCase    ,				mean=__UpperCAmelCase    ,				std=__UpperCAmelCase       ) for image in images]

						SCREAMING_SNAKE_CASE__								=      [to_channel_dimension_format(__UpperCAmelCase    ,				__UpperCAmelCase       ) for image in images]

						SCREAMING_SNAKE_CASE__								=      {"""pixel_values""": images}
						return BatchFeature(data=__UpperCAmelCase    ,				tensor_type=__UpperCAmelCase       )





"""simple docstring"""




import functools
import operator

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


A_							:			List[Any]											= logging.get_logger(__name__)

A_							:			Dict											= {
    "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    lowerCamelCase						(A__			):
			lowerCamelCase__   :		int							=							'unispeech'

			def __init__(					self				:						Union[str, Any]    ,				__UpperCAmelCase				:						List[Any]=3_2    ,				__UpperCAmelCase				:						Union[str, Any]=7_6_8    ,				__UpperCAmelCase				:						Tuple=1_2    ,				__UpperCAmelCase				:						Dict=1_2    ,				__UpperCAmelCase				:						Optional[Any]=3_0_7_2    ,				__UpperCAmelCase				:						Optional[Any]="gelu"    ,				__UpperCAmelCase				:						Union[str, Any]=0.1    ,				__UpperCAmelCase				:						List[Any]=0.1    ,				__UpperCAmelCase				:						List[str]=0.1    ,				__UpperCAmelCase				:						List[str]=0.0    ,				__UpperCAmelCase				:						Tuple=0.0    ,				__UpperCAmelCase				:						List[Any]=0.1    ,				__UpperCAmelCase				:						Union[str, Any]=0.1    ,				__UpperCAmelCase				:						Union[str, Any]=0.02    ,				__UpperCAmelCase				:						Union[str, Any]=1e-5    ,				__UpperCAmelCase				:						List[Any]="group"    ,				__UpperCAmelCase				:						Union[str, Any]="gelu"    ,				__UpperCAmelCase				:						Any=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)    ,				__UpperCAmelCase				:						List[str]=(5, 2, 2, 2, 2, 2, 2)    ,				__UpperCAmelCase				:						int=(1_0, 3, 3, 3, 3, 2, 2)    ,				__UpperCAmelCase				:						str=False    ,				__UpperCAmelCase				:						Any=1_2_8    ,				__UpperCAmelCase				:						str=1_6    ,				__UpperCAmelCase				:						Optional[Any]=False    ,				__UpperCAmelCase				:						Optional[int]=True    ,				__UpperCAmelCase				:						Union[str, Any]=0.05    ,				__UpperCAmelCase				:						str=1_0    ,				__UpperCAmelCase				:						Optional[Any]=2    ,				__UpperCAmelCase				:						List[Any]=0.0    ,				__UpperCAmelCase				:						Tuple=1_0    ,				__UpperCAmelCase				:						Tuple=0    ,				__UpperCAmelCase				:						Tuple=3_2_0    ,				__UpperCAmelCase				:						Any=2    ,				__UpperCAmelCase				:						Optional[int]=0.1    ,				__UpperCAmelCase				:						Any=1_0_0    ,				__UpperCAmelCase				:						str=2_5_6    ,				__UpperCAmelCase				:						Dict=2_5_6    ,				__UpperCAmelCase				:						Dict=0.1    ,				__UpperCAmelCase				:						List[str]="mean"    ,				__UpperCAmelCase				:						Optional[Any]=False    ,				__UpperCAmelCase				:						List[Any]=False    ,				__UpperCAmelCase				:						str=2_5_6    ,				__UpperCAmelCase				:						Dict=8_0    ,				__UpperCAmelCase				:						List[Any]=0    ,				__UpperCAmelCase				:						int=1    ,				__UpperCAmelCase				:						Optional[int]=2    ,				__UpperCAmelCase				:						Any=0.5    ,				**__UpperCAmelCase				:						List[str]    ,				)   ->    Tuple:
						super().__init__(**__UpperCAmelCase    ,				pad_token_id=__UpperCAmelCase    ,				bos_token_id=__UpperCAmelCase    ,				eos_token_id=__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      hidden_size
						SCREAMING_SNAKE_CASE__								=      feat_extract_norm
						SCREAMING_SNAKE_CASE__								=      feat_extract_activation
						SCREAMING_SNAKE_CASE__								=      list(__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      list(__UpperCAmelCase       )
						SCREAMING_SNAKE_CASE__								=      list(__UpperCAmelCase       )
						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 					SCREAMING_SNAKE_CASE				(					self				:						int       )   ->    Optional[Any]:
						return functools.reduce(operator.mul    ,				self.conv_stride    ,				1       )


