




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_   		=     logging.get_logger(__name__)

class  _lowerCamelCase						(			_SCREAMING_SNAKE_CASE   ):

      """simple docstring"""

      lowerCAmelCase__			: Any    =					["pixel_values"]







      def __init__(     self					: List[str] ,       snake_case					: bool = True ,       snake_case					: Optional[Dict[str, int]] = None ,       snake_case					: PILImageResampling = PILImageResampling.BICUBIC ,       snake_case					: bool = True ,       snake_case					: bool = True ,       snake_case					: Union[int, float] = 1 / 255 ,       snake_case					: Dict[str, int] = None ,       snake_case					: bool = True ,       snake_case					: Optional[Union[float, List[float]]] = None ,       snake_case					: Optional[Union[float, List[float]]] = None ,       **snake_case					: Tuple ,       ):
          super().__init__(**snake_case				)
          __UpperCamelCase  		=						size if size is not None else {'''height''': 224, '''width''': 224}
          __UpperCamelCase  		=						get_size_dict(snake_case				)
          __UpperCamelCase  		=						crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
          __UpperCamelCase  		=						get_size_dict(snake_case ,       default_to_square=snake_case ,       param_name='''crop_size'''				)

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







      def       snake_case	(     self					: Dict ,       snake_case					: np.ndarray ,       snake_case					: Dict[str, int] ,       snake_case					: PILImageResampling = PILImageResampling.BILINEAR ,       snake_case					: Optional[Union[str, ChannelDimension]] = None ,       **snake_case					: Dict ,       ):
          __UpperCamelCase  		=						get_size_dict(snake_case				)

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







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







      def       snake_case	(     self					: int ,       snake_case					: np.ndarray ,       snake_case					: float ,       snake_case					: Optional[Union[str, ChannelDimension]] = None ,       **snake_case					: Tuple				):
          return rescale(snake_case ,       scale=snake_case ,       data_format=snake_case ,       **snake_case				)







      def       snake_case	(     self					: Optional[int] ,       snake_case					: np.ndarray ,       snake_case					: Union[float, List[float]] ,       snake_case					: Union[float, List[float]] ,       snake_case					: Optional[Union[str, ChannelDimension]] = None ,       **snake_case					: List[str] ,       ):
          return normalize(snake_case ,       mean=snake_case ,       std=snake_case ,       data_format=snake_case ,       **snake_case				)







      def       snake_case	(     self					: List[Any] ,       snake_case					: ImageInput ,       snake_case					: Optional[bool] = None ,       snake_case					: Dict[str, int] = None ,       snake_case					: PILImageResampling = None ,       snake_case					: bool = None ,       snake_case					: int = None ,       snake_case					: Optional[bool] = None ,       snake_case					: Optional[float] = None ,       snake_case					: Optional[bool] = None ,       snake_case					: Optional[Union[float, List[float]]] = None ,       snake_case					: Optional[Union[float, List[float]]] = None ,       snake_case					: Optional[Union[str, TensorType]] = None ,       snake_case					: Union[str, ChannelDimension] = ChannelDimension.FIRST ,       **snake_case					: Tuple ,       ):
          __UpperCamelCase  		=						do_resize if do_resize is not None else self.do_resize
          __UpperCamelCase  		=						do_rescale if do_rescale is not None else self.do_rescale
          __UpperCamelCase  		=						do_normalize if do_normalize is not None else self.do_normalize
          __UpperCamelCase  		=						do_center_crop if do_center_crop is not None else self.do_center_crop
          __UpperCamelCase  		=						crop_size if crop_size is not None else self.crop_size
          __UpperCamelCase  		=						get_size_dict(snake_case ,       param_name='''crop_size''' ,       default_to_square=snake_case				)
          __UpperCamelCase  		=						resample if resample is not None else self.resample
          __UpperCamelCase  		=						rescale_factor if rescale_factor is not None else self.rescale_factor
          __UpperCamelCase  		=						image_mean if image_mean is not None else self.image_mean
          __UpperCamelCase  		=						image_std if image_std is not None else self.image_std

          __UpperCamelCase  		=						size if size is not None else self.size
          __UpperCamelCase  		=						get_size_dict(snake_case				)

          if not is_batched(snake_case				):
              __UpperCamelCase  		=						[images]

          if not valid_images(snake_case				):
              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.
          __UpperCamelCase  		=						[to_numpy_array(snake_case				) for image in images]

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

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

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

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

          __UpperCamelCase  		=						[to_channel_dimension_format(snake_case ,       snake_case				) for image in images]

          __UpperCamelCase  		=						{'''pixel_values''': images}
          return BatchFeature(data=snake_case ,       tensor_type=snake_case				)












import functools
import operator

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


a_   		=     logging.get_logger(__name__)

a_   		=     {
    "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						(			_SCREAMING_SNAKE_CASE   ):

      """simple docstring"""

      lowerCAmelCase__			: Dict    =					"unispeech"







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

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

          # ctc loss
          __UpperCamelCase  		=						ctc_loss_reduction
          __UpperCamelCase  		=						ctc_zero_infinity

          # pretraining loss
          __UpperCamelCase  		=						replace_prob







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






