






import functools
import operator

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


__UpperCAmelCase								=			logging.get_logger(__name__)

__UpperCAmelCase								=			{
    '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"""






  lowerCamelCase   :      int										="unispeech"







  def __init__(      self			:   Optional[Any]	,							lowerCAmelCase			:   List[Any]=32	,							lowerCAmelCase			:   Dict=7_68	,							lowerCAmelCase			:   str=12	,							lowerCAmelCase			:   Any=12	,							lowerCAmelCase			:   Optional[Any]=30_72	,							lowerCAmelCase			:   Optional[Any]="gelu"	,							lowerCAmelCase			:   List[Any]=0.1	,							lowerCAmelCase			:   Union[str, Any]=0.1	,							lowerCAmelCase			:   Optional[Any]=0.1	,							lowerCAmelCase			:   List[Any]=0.0	,							lowerCAmelCase			:   Optional[int]=0.0	,							lowerCAmelCase			:   List[Any]=0.1	,							lowerCAmelCase			:   str=0.1	,							lowerCAmelCase			:   Optional[Any]=0.02	,							lowerCAmelCase			:   Dict=1e-5	,							lowerCAmelCase			:   int="group"	,							lowerCAmelCase			:   Tuple="gelu"	,							lowerCAmelCase			:   List[Any]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)	,							lowerCAmelCase			:   Tuple=(5, 2, 2, 2, 2, 2, 2)	,							lowerCAmelCase			:   Any=(10, 3, 3, 3, 3, 2, 2)	,							lowerCAmelCase			:   Optional[Any]=False	,							lowerCAmelCase			:   Tuple=1_28	,							lowerCAmelCase			:   List[str]=16	,							lowerCAmelCase			:   Any=False	,							lowerCAmelCase			:   Any=True	,							lowerCAmelCase			:   Optional[int]=0.05	,							lowerCAmelCase			:   str=10	,							lowerCAmelCase			:   Optional[int]=2	,							lowerCAmelCase			:   Any=0.0	,							lowerCAmelCase			:   Dict=10	,							lowerCAmelCase			:   List[str]=0	,							lowerCAmelCase			:   str=3_20	,							lowerCAmelCase			:   Optional[Any]=2	,							lowerCAmelCase			:   str=0.1	,							lowerCAmelCase			:   Any=1_00	,							lowerCAmelCase			:   str=2_56	,							lowerCAmelCase			:   Optional[Any]=2_56	,							lowerCAmelCase			:   List[Any]=0.1	,							lowerCAmelCase			:   int="mean"	,							lowerCAmelCase			:   List[str]=False	,							lowerCAmelCase			:   Tuple=False	,							lowerCAmelCase			:   Tuple=2_56	,							lowerCAmelCase			:   Union[str, Any]=80	,							lowerCAmelCase			:   Optional[int]=0	,							lowerCAmelCase			:   int=1	,							lowerCAmelCase			:   List[str]=2	,							lowerCAmelCase			:   int=0.5	,							**lowerCAmelCase			:   List[Any]	,							)							->     Optional[int]:






     """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_   )
     __lowerCAmelCase  :      Union[str, Any]    =						hidden_size
     __lowerCAmelCase  :      Optional[Any]    =						feat_extract_norm
     __lowerCAmelCase  :      Optional[int]    =						feat_extract_activation
     __lowerCAmelCase  :      Dict    =						list(SCREAMING_SNAKE_CASE_   )
     __lowerCAmelCase  :      str    =						list(SCREAMING_SNAKE_CASE_   )
     __lowerCAmelCase  :      Any    =						list(SCREAMING_SNAKE_CASE_   )
     __lowerCAmelCase  :      List[Any]    =						conv_bias
     __lowerCAmelCase  :      Tuple    =						num_conv_pos_embeddings
     __lowerCAmelCase  :      str    =						num_conv_pos_embedding_groups
     __lowerCAmelCase  :      List[Any]    =						len(self.conv_dim   )
     __lowerCAmelCase  :      Tuple    =						num_hidden_layers
     __lowerCAmelCase  :      Optional[int]    =						intermediate_size
     __lowerCAmelCase  :      Optional[Any]    =						hidden_act
     __lowerCAmelCase  :      str    =						num_attention_heads
     __lowerCAmelCase  :      Tuple    =						hidden_dropout
     __lowerCAmelCase  :      Dict    =						attention_dropout
     __lowerCAmelCase  :      Optional[int]    =						activation_dropout
     __lowerCAmelCase  :      List[str]    =						feat_proj_dropout
     __lowerCAmelCase  :      int    =						final_dropout
     __lowerCAmelCase  :      Dict    =						layerdrop
     __lowerCAmelCase  :      Optional[int]    =						layer_norm_eps
     __lowerCAmelCase  :      Optional[int]    =						initializer_range
     __lowerCAmelCase  :      Optional[int]    =						num_ctc_classes
     __lowerCAmelCase  :      Any    =						vocab_size
     __lowerCAmelCase  :      int    =						do_stable_layer_norm
     __lowerCAmelCase  :      Optional[int]    =						use_weighted_layer_sum
     __lowerCAmelCase  :      List[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
     __lowerCAmelCase  :      Any    =						apply_spec_augment
     __lowerCAmelCase  :      List[Any]    =						mask_time_prob
     __lowerCAmelCase  :      Any    =						mask_time_length
     __lowerCAmelCase  :      Any    =						mask_time_min_masks
     __lowerCAmelCase  :      Union[str, Any]    =						mask_feature_prob
     __lowerCAmelCase  :      List[Any]    =						mask_feature_length
     __lowerCAmelCase  :      Tuple    =						mask_feature_min_masks

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

     # ctc loss
     __lowerCAmelCase  :      Optional[Any]    =						ctc_loss_reduction
     __lowerCAmelCase  :      List[Any]    =						ctc_zero_infinity

     # pretraining loss
     __lowerCAmelCase  :      Tuple    =						replace_prob







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Dict:






     """simple docstring"""







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





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import MobileViTImageProcessor



class SCREAMING_SNAKE_CASE     (  unittest.TestCase			):
  """simple docstring"""






  def __init__(      self			:   List[Any]	,							lowerCAmelCase			:   List[str]	,							lowerCAmelCase			:   Optional[Any]=7	,							lowerCAmelCase			:   List[str]=3	,							lowerCAmelCase			:   int=18	,							lowerCAmelCase			:   int=30	,							lowerCAmelCase			:   Optional[int]=4_00	,							lowerCAmelCase			:   Optional[Any]=True	,							lowerCAmelCase			:   Dict=None	,							lowerCAmelCase			:   List[str]=True	,							lowerCAmelCase			:   Tuple=None	,							lowerCAmelCase			:   Any=True	,							)							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[Any]    =						size if size is not None else {"""shortest_edge""": 20}
     __lowerCAmelCase  :      Any    =						crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
     __lowerCAmelCase  :      str    =						parent
     __lowerCAmelCase  :      List[str]    =						batch_size
     __lowerCAmelCase  :      int    =						num_channels
     __lowerCAmelCase  :      List[str]    =						image_size
     __lowerCAmelCase  :      Optional[int]    =						min_resolution
     __lowerCAmelCase  :      List[str]    =						max_resolution
     __lowerCAmelCase  :      List[Any]    =						do_resize
     __lowerCAmelCase  :      Optional[int]    =						size
     __lowerCAmelCase  :      List[Any]    =						do_center_crop
     __lowerCAmelCase  :      Optional[Any]    =						crop_size
     __lowerCAmelCase  :      int    =						do_flip_channel_order







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Union[str, Any]:






     """simple docstring"""







     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_center_crop": self.do_center_crop,
         "crop_size": self.crop_size,
         "do_flip_channel_order": self.do_flip_channel_order,
     }






@require_torch
@require_vision
class SCREAMING_SNAKE_CASE     (  a_       ,							unittest.TestCase			):
  """simple docstring"""






  lowerCamelCase   :      List[str]										=MobileViTImageProcessor if is_vision_available() else None







  def 	SCREAMING_SNAKE_CASE   (      self			:   Any   )							->     Tuple:






     """simple docstring"""







     __lowerCAmelCase  :      List[str]    =						MobileViTImageProcessingTester(self   )







  @property
  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Dict:






     """simple docstring"""







     return self.image_processor_tester.prepare_image_processor_dict()







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      Optional[Any]    =						self.image_processing_class(**self.image_processor_dict   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_resize"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""size"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_center_crop"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""center_crop"""   )   )
     self.assertTrue(hasattr(lowerCAmelCase	,							"""do_flip_channel_order"""   )   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     List[Any]:






     """simple docstring"""







     __lowerCAmelCase  :      List[str]    =						self.image_processing_class.from_dict(self.image_processor_dict   )
     self.assertEqual(image_processor.size	,							{"""shortest_edge""": 20}   )
     self.assertEqual(image_processor.crop_size	,							{"""height""": 18, """width""": 18}   )

     __lowerCAmelCase  :      Optional[Any]    =						self.image_processing_class.from_dict(self.image_processor_dict	,							size=42	,							crop_size=84   )
     self.assertEqual(image_processor.size	,							{"""shortest_edge""": 42}   )
     self.assertEqual(image_processor.crop_size	,							{"""height""": 84, """width""": 84}   )







  def 	SCREAMING_SNAKE_CASE   (      self			:   str   )							->     int:






     """simple docstring"""







     pass







  def 	SCREAMING_SNAKE_CASE   (      self			:   Tuple   )							->     List[str]:






     """simple docstring"""







     __lowerCAmelCase  :      Any    =						self.image_processing_class(**self.image_processor_dict   )
     # create random PIL images
     __lowerCAmelCase  :      Union[str, Any]    =						prepare_image_inputs(self.image_processor_tester	,							equal_resolution=lowerCAmelCase   )
     for image in image_inputs:
        self.assertIsInstance(lowerCAmelCase	,							Image.Image   )

     # Test not batched input
     __lowerCAmelCase  :      List[Any]    =						image_processing(image_inputs[0]	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)

     # Test batched
     __lowerCAmelCase  :      str    =						image_processing(lowerCAmelCase	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)







  def 	SCREAMING_SNAKE_CASE   (      self			:   int   )							->     Optional[int]:






     """simple docstring"""







     __lowerCAmelCase  :      List[Any]    =						self.image_processing_class(**self.image_processor_dict   )
     # create random numpy tensors
     __lowerCAmelCase  :      Any    =						prepare_image_inputs(self.image_processor_tester	,							equal_resolution=lowerCAmelCase	,							numpify=lowerCAmelCase   )
     for image in image_inputs:
        self.assertIsInstance(lowerCAmelCase	,							np.ndarray   )

     # Test not batched input
     __lowerCAmelCase  :      Optional[Any]    =						image_processing(image_inputs[0]	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)

     # Test batched
     __lowerCAmelCase  :      Tuple    =						image_processing(lowerCAmelCase	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)







  def 	SCREAMING_SNAKE_CASE   (      self			:   Optional[int]   )							->     Any:






     """simple docstring"""







     __lowerCAmelCase  :      Tuple    =						self.image_processing_class(**self.image_processor_dict   )
     # create random PyTorch tensors
     __lowerCAmelCase  :      str    =						prepare_image_inputs(self.image_processor_tester	,							equal_resolution=lowerCAmelCase	,							torchify=lowerCAmelCase   )
     for image in image_inputs:
        self.assertIsInstance(lowerCAmelCase	,							torch.Tensor   )

     # Test not batched input
     __lowerCAmelCase  :      Optional[int]    =						image_processing(image_inputs[0]	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)

     # Test batched
     __lowerCAmelCase  :      Tuple    =						image_processing(lowerCAmelCase	,							return_tensors="""pt"""   ).pixel_values
     self.assertEqual(
         encoded_images.shape	,							(
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["""height"""],
             self.image_processor_tester.crop_size["""width"""],
         )	,							)


