






'''simple docstring'''

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 MobileNetVaImageProcessor






class 				__magic_name__  (						unittest.TestCase					):







	"""simple docstring"""



	def __init__(				self	,   _lowercase	,   _lowercase=7	,   _lowercase=3	,   _lowercase=18	,   _lowercase=30	,   _lowercase=400	,   _lowercase=True	,   _lowercase=None	,   _lowercase=True	,   _lowercase=None	,   )    ->	Tuple:
							lowercase_   : Tuple   	=      size if size is not None else {'shortest_edge': 20}
							lowercase_   : str   	=      crop_size if crop_size is not None else {'height': 18, 'width': 18}
							lowercase_   : Union[str, Any]   	=      parent
							lowercase_   : Optional[int]   	=      batch_size
							lowercase_   : List[str]   	=      num_channels
							lowercase_   : Union[str, Any]   	=      image_size
							lowercase_   : Any   	=      min_resolution
							lowercase_   : int   	=      max_resolution
							lowercase_   : List[Any]   	=      do_resize
							lowercase_   : Union[str, Any]   	=      size
							lowercase_   : Dict   	=      do_center_crop
							lowercase_   : List[Any]   	=      crop_size







	def 							lowerCamelCase__		(				self							)    ->	Optional[int]:
							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							}






@require_torch
@require_vision
class 				__magic_name__  (						UpperCAmelCase__,    unittest.TestCase					):







	"""simple docstring"""



	SCREAMING_SNAKE_CASE_       :   Tuple   =	MobileNetVaImageProcessor if is_vision_available() else None
	def 							lowerCamelCase__		(				self							)    ->	Optional[Any]:
							lowercase_   : Tuple   	=      MobileNetVaImageProcessingTester(self							)
	@property
	def 							lowerCamelCase__		(				self							)    ->	Dict:
							return self.image_processor_tester.prepare_image_processor_dict()
	def 							lowerCamelCase__		(				self							)    ->	List[Any]:
							lowercase_   : Optional[int]   	=      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'							)							)
	def 							lowerCamelCase__		(				self							)    ->	Tuple:
							lowercase_   : Union[str, Any]   	=      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}							)

							lowercase_   : Dict   	=      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 							lowerCamelCase__		(				self							)    ->	Any:
							pass
	def 							lowerCamelCase__		(				self							)    ->	List[Any]:
							# Initialize image_processing
							lowercase_   : List[str]   	=      self.image_processing_class(**self.image_processor_dict							)
							# create random PIL images
							lowercase_   : int   	=      prepare_image_inputs(self.image_processor_tester	,   equal_resolution=_lowerCAmelCase							)
							for image in image_inputs:
													self.assertIsInstance(_lowerCAmelCase	,   Image.Image							)

							# Test not batched input
							lowercase_   : List[str]   	=      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
							lowercase_   : List[Any]   	=      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 							lowerCamelCase__		(				self							)    ->	Tuple:
							# Initialize image_processing
							lowercase_   : Dict   	=      self.image_processing_class(**self.image_processor_dict							)
							# create random numpy tensors
							lowercase_   : Dict   	=      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
							lowercase_   : str   	=      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
							lowercase_   : List[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 							lowerCamelCase__		(				self							)    ->	Tuple:
							# Initialize image_processing
							lowercase_   : List[str]   	=      self.image_processing_class(**self.image_processor_dict							)
							# create random PyTorch tensors
							lowercase_   : List[Any]   	=      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
							lowercase_   : 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
							lowercase_   : Optional[int]   	=      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'],
							    )	,   )






import functools
import operator

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


_lowerCamelCase							=      logging.get_logger(__name__)

_lowerCamelCase							=      {
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}


class        UpperCAmelCase__				(							UpperCAmelCase__				):



     '''simple docstring'''
     _SCREAMING_SNAKE_CASE      :					Dict     					=    "hubert"
     def __init__(				self ,    _lowerCAmelCase=32 ,    _lowerCAmelCase=768 ,    _lowerCAmelCase=12 ,    _lowerCAmelCase=12 ,    _lowerCAmelCase=3_072 ,    _lowerCAmelCase="gelu" ,    _lowerCAmelCase=0.1 ,    _lowerCAmelCase=0.1 ,    _lowerCAmelCase=0.1 ,    _lowerCAmelCase=True ,    _lowerCAmelCase=0.0 ,    _lowerCAmelCase=0.1 ,    _lowerCAmelCase=0.1 ,    _lowerCAmelCase=0.02 ,    _lowerCAmelCase=1E-5 ,    _lowerCAmelCase="group" ,    _lowerCAmelCase="gelu" ,    _lowerCAmelCase=(512, 512, 512, 512, 512, 512, 512) ,    _lowerCAmelCase=(5, 2, 2, 2, 2, 2, 2) ,    _lowerCAmelCase=(10, 3, 3, 3, 3, 2, 2) ,    _lowerCAmelCase=False ,    _lowerCAmelCase=128 ,    _lowerCAmelCase=16 ,    _lowerCAmelCase=False ,    _lowerCAmelCase=True ,    _lowerCAmelCase=0.05 ,    _lowerCAmelCase=10 ,    _lowerCAmelCase=2 ,    _lowerCAmelCase=0.0 ,    _lowerCAmelCase=10 ,    _lowerCAmelCase=0 ,    _lowerCAmelCase="sum" ,    _lowerCAmelCase=False ,    _lowerCAmelCase=False ,    _lowerCAmelCase=256 ,    _lowerCAmelCase=0 ,    _lowerCAmelCase=1 ,    _lowerCAmelCase=2 ,    **_lowerCAmelCase ,    ):
            super().__init__(**_lowerCAmelCase ,    pad_token_id=_lowerCAmelCase ,    bos_token_id=_lowerCAmelCase ,    eos_token_id=_lowerCAmelCase	)
            a			   =hidden_size
            a			   =feat_extract_norm
            a			   =feat_extract_activation
            a			   =list(_lowerCAmelCase	)
            a			   =list(_lowerCAmelCase	)
            a			   =list(_lowerCAmelCase	)
            a			   =conv_bias
            a			   =num_conv_pos_embeddings
            a			   =num_conv_pos_embedding_groups
            a			   =len(self.conv_dim	)
            a			   =num_hidden_layers
            a			   =intermediate_size
            a			   =hidden_act
            a			   =num_attention_heads
            a			   =hidden_dropout
            a			   =attention_dropout
            a			   =activation_dropout
            a			   =feat_proj_layer_norm
            a			   =feat_proj_dropout
            a			   =final_dropout
            a			   =layerdrop
            a			   =layer_norm_eps
            a			   =initializer_range
            a			   =vocab_size
            a			   =do_stable_layer_norm
            a			   =use_weighted_layer_sum
            a			   =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
            a			   =apply_spec_augment
            a			   =mask_time_prob
            a			   =mask_time_length
            a			   =mask_time_min_masks
            a			   =mask_feature_prob
            a			   =mask_feature_length
            a			   =mask_feature_min_masks

            # ctc loss
            a			   =ctc_loss_reduction
            a			   =ctc_zero_infinity






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