




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 PoolFormerImageProcessor

class  _lowerCamelCase						(			unittest.TestCase   ):

      """simple docstring"""

      def __init__(     self					: List[str] ,       snake_case					: List[Any] ,       snake_case					: Tuple=7 ,       snake_case					: Optional[Any]=3 ,       snake_case					: Tuple=30 ,       snake_case					: Dict=400 ,       snake_case					: Optional[int]=True ,       snake_case					: Union[str, Any]=None ,       snake_case					: Any=0.9 ,       snake_case					: Optional[Any]=None ,       snake_case					: Union[str, Any]=True ,       snake_case					: List[str]=[0.5, 0.5, 0.5] ,       snake_case					: Dict=[0.5, 0.5, 0.5] ,       ):
          __UpperCamelCase  		=						size if size is not None else {'''shortest_edge''': 30}
          __UpperCamelCase  		=						crop_size if crop_size is not None else {'''height''': 30, '''width''': 30}
          __UpperCamelCase  		=						parent
          __UpperCamelCase  		=						batch_size
          __UpperCamelCase  		=						num_channels
          __UpperCamelCase  		=						min_resolution
          __UpperCamelCase  		=						max_resolution
          __UpperCamelCase  		=						do_resize_and_center_crop
          __UpperCamelCase  		=						size
          __UpperCamelCase  		=						crop_pct
          __UpperCamelCase  		=						crop_size
          __UpperCamelCase  		=						do_normalize
          __UpperCamelCase  		=						image_mean
          __UpperCamelCase  		=						image_std







      def       snake_case	(     self					: Tuple				):
          return {
              "size": self.size,
              "do_resize_and_center_crop": self.do_resize_and_center_crop,
              "crop_pct": self.crop_pct,
              "crop_size": self.crop_size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
          }







@require_torch
@require_vision
class  _lowerCamelCase						(			_SCREAMING_SNAKE_CASE							,			unittest.TestCase   ):

      """simple docstring"""

      lowerCAmelCase__			: Dict    =					PoolFormerImageProcessor if is_vision_available() else None







      def       snake_case	(     self					: int				):
          __UpperCamelCase  		=						PoolFormerImageProcessingTester(self				)







      @property
      def       snake_case	(     self					: str				):
          return self.image_processor_tester.prepare_image_processor_dict()







      def       snake_case	(     self					: str				):
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          self.assertTrue(hasattr(snake_case ,       '''do_resize_and_center_crop'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''size'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''crop_pct'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''do_normalize'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''image_mean'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''image_std'''				)				)







      def       snake_case	(     self					: Optional[int]				):
          __UpperCamelCase  		=						self.image_processing_class.from_dict(self.image_processor_dict				)
          self.assertEqual(image_processor.size ,       {'''shortest_edge''': 30}				)
          self.assertEqual(image_processor.crop_size ,       {'''height''': 30, '''width''': 30}				)

          __UpperCamelCase  		=						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       snake_case	(     self					: Optional[Any]				):
          pass







      def       snake_case	(     self					: str				):
          # Initialize image_processing
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random PIL images
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       Image.Image				)

          # Test not batched input
          __UpperCamelCase  		=						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
          __UpperCamelCase  		=						image_processing(snake_case ,       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       snake_case	(     self					: Union[str, Any]				):
          # Initialize image_processing
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random numpy tensors
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case ,       numpify=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       np.ndarray				)

          # Test not batched input
          __UpperCamelCase  		=						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
          __UpperCamelCase  		=						image_processing(snake_case ,       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       snake_case	(     self					: Optional[int]				):
          # Initialize image_processing
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random PyTorch tensors
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case ,       torchify=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       torch.Tensor				)

          # Test not batched input
          __UpperCamelCase  		=						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
          __UpperCamelCase  		=						image_processing(snake_case ,       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'''],
              ) ,       )












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				)






