code: 
  
  
  
  
  
  
  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
  
  
  if is_torch_available():
     import torch
  
  if is_vision_available():
     from PIL import Image
  
     from transformers import CLIPImageProcessor
  
  class 					snake_case_							(       unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     def __init__(    self:	str   ,       snake_case__:	Any   ,       snake_case__:	Optional[Any]=7   ,       snake_case__:	Optional[Any]=3   ,       snake_case__:	List[str]=18   ,       snake_case__:	Any=30   ,       snake_case__:	List[Any]=400   ,       snake_case__:	Any=True   ,       snake_case__:	Tuple=None   ,       snake_case__:	Any=True   ,       snake_case__:	List[Any]=None   ,       snake_case__:	Optional[int]=True   ,       snake_case__:	Optional[int]=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]   ,       snake_case__:	str=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]   ,       snake_case__:	int=True   ,       )  ->		List[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	size if size is not None else {'shortest_edge': 20}
           _lowercase     =	crop_size if crop_size is not None else {'height': 18, 'width': 18}
           _lowercase     =	parent
           _lowercase     =	batch_size
           _lowercase     =	num_channels
           _lowercase     =	image_size
           _lowercase     =	min_resolution
           _lowercase     =	max_resolution
           _lowercase     =	do_resize
           _lowercase     =	size
           _lowercase     =	do_center_crop
           _lowercase     =	crop_size
           _lowercase     =	do_normalize
           _lowercase     =	image_mean
           _lowercase     =	image_std
           _lowercase     =	do_convert_rgb
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	int	)  ->		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_normalize": self.do_normalize,
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_convert_rgb": self.do_convert_rgb,
           }
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Optional[int]=False   ,       snake_case__:	int=False   ,       snake_case__:	Dict=False	)  ->		int:
  
  
           """simple docstring"""
  
  
  
           assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
           if equal_resolution:
                 _lowercase     =	[]
                 for i in range(self.batch_size	):
                       image_inputs.append(
                           np.random.randint(
                               255   ,       size=(self.num_channels, self.max_resolution, self.max_resolution)   ,       dtype=np.uinta	)	)
           else:
                 _lowercase     =	[]
                 for i in range(self.batch_size	):
                       _lowercase ,    _lowercase     =	np.random.choice(np.arange(self.min_resolution   ,       self.max_resolution	)   ,       2	)
                       image_inputs.append(np.random.randint(255   ,       size=(self.num_channels, width, height)   ,       dtype=np.uinta	)	)
  
           if not numpify and not torchify:
                 # PIL expects the channel dimension as last dimension
                 _lowercase     =	[Image.fromarray(np.moveaxis(snake_case__   ,       0   ,       -1	)	) for x in image_inputs]
  
           if torchify:
                 _lowercase     =	[torch.from_numpy(snake_case__	) for x in image_inputs]
  
           return image_inputs
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 					snake_case_							(       lowercase_      ,			unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						CLIPImageProcessor if is_vision_available() else None
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Tuple	)  ->		Union[str, Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	CLIPImageProcessingTester(self	)
  
     @property
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		List[str]:
  
  
           """simple docstring"""
  
  
  
           return self.image_processor_tester.prepare_image_processor_dict()
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	str	)  ->		Any:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           self.assertTrue(hasattr(snake_case__   ,       'do_resize'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'size'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_center_crop'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'center_crop'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_normalize'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'image_mean'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'image_std'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_convert_rgb'	)	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	List[Any]	)  ->		int:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	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     =	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:	List[str]	)  ->		str:
  
  
           """simple docstring"""
  
  
  
           pass
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		List[str]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           # create random PIL images
           _lowercase     =	self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__	)
           for image in image_inputs:
                 self.assertIsInstance(snake_case__   ,       Image.Image	)
  
           # Test not batched input
           _lowercase     =	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     =	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 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		Optional[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           # create random numpy tensors
           _lowercase     =	self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__   ,       numpify=snake_case__	)
           for image in image_inputs:
                 self.assertIsInstance(snake_case__   ,       np.ndarray	)
  
           # Test not batched input
           _lowercase     =	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     =	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 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		List[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           # create random PyTorch tensors
           _lowercase     =	self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__   ,       torchify=snake_case__	)
           for image in image_inputs:
                 self.assertIsInstance(snake_case__   ,       torch.Tensor	)
  
           # Test not batched input
           _lowercase     =	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     =	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'],
               )   ,       )
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 					snake_case_							(       lowercase_      ,			unittest.TestCase      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						CLIPImageProcessor if is_vision_available() else None
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]	)  ->		Tuple:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	CLIPImageProcessingTester(self   ,       num_channels=4	)
           _lowercase     =	3
  
     @property
     def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		Optional[int]:
  
  
           """simple docstring"""
  
  
  
           return self.image_processor_tester.prepare_image_processor_dict()
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Any	)  ->		List[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           self.assertTrue(hasattr(snake_case__   ,       'do_resize'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'size'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_center_crop'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'center_crop'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_normalize'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'image_mean'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'image_std'	)	)
           self.assertTrue(hasattr(snake_case__   ,       'do_convert_rgb'	)	)
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]	)  ->		List[Any]:
  
  
           """simple docstring"""
  
  
  
           pass
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]	)  ->		Optional[Any]:
  
  
           """simple docstring"""
  
  
  
           _lowercase     =	self.image_processing_class(**self.image_processor_dict	)
           # create random PIL images
           _lowercase     =	self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__	)
           for image in image_inputs:
                 self.assertIsInstance(snake_case__   ,       Image.Image	)
  
           # Test not batched input
           _lowercase     =	image_processing(image_inputs[0]   ,       return_tensors='pt'	).pixel_values
           self.assertEqual(
               encoded_images.shape   ,       (
                   1,
                   self.expected_encoded_image_num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )   ,       )
  
           # Test batched
           _lowercase     =	image_processing(snake_case__   ,       return_tensors='pt'	).pixel_values
           self.assertEqual(
               encoded_images.shape   ,       (
                   self.image_processor_tester.batch_size,
                   self.expected_encoded_image_num_channels,
                   self.image_processor_tester.crop_size['height'],
                   self.image_processor_tester.crop_size['width'],
               )   ,       )
  
style_context: 
  
  
  
  
  
  
  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 					snake_case_							(       lowercase_      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						"""hubert"""
  
     def __init__(    self:	Any   ,       snake_case__:	str=32   ,       snake_case__:	int=768   ,       snake_case__:	Dict=12   ,       snake_case__:	Optional[int]=12   ,       snake_case__:	List[str]=3_072   ,       snake_case__:	Optional[Any]="gelu"   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	Optional[int]=0.1   ,       snake_case__:	List[str]=True   ,       snake_case__:	Union[str, Any]=0.0   ,       snake_case__:	Union[str, Any]=0.1   ,       snake_case__:	List[str]=0.1   ,       snake_case__:	List[Any]=0.02   ,       snake_case__:	Dict=1E-5   ,       snake_case__:	Any="group"   ,       snake_case__:	Union[str, Any]="gelu"   ,       snake_case__:	List[str]=(512, 512, 512, 512, 512, 512, 512)   ,       snake_case__:	Union[str, Any]=(5, 2, 2, 2, 2, 2, 2)   ,       snake_case__:	Any=(10, 3, 3, 3, 3, 2, 2)   ,       snake_case__:	int=False   ,       snake_case__:	Any=128   ,       snake_case__:	Dict=16   ,       snake_case__:	Optional[Any]=False   ,       snake_case__:	Tuple=True   ,       snake_case__:	int=0.05   ,       snake_case__:	List[Any]=10   ,       snake_case__:	Tuple=2   ,       snake_case__:	List[Any]=0.0   ,       snake_case__:	Optional[int]=10   ,       snake_case__:	Optional[int]=0   ,       snake_case__:	Union[str, Any]="sum"   ,       snake_case__:	Union[str, Any]=False   ,       snake_case__:	int=False   ,       snake_case__:	Any=256   ,       snake_case__:	Union[str, Any]=0   ,       snake_case__:	Optional[int]=1   ,       snake_case__:	List[str]=2   ,       **snake_case__:	Optional[int]   ,       )  ->		Any:
  
  
         """simple docstring"""
  
  
  
         super().__init__(**snake_case__   ,       pad_token_id=snake_case__   ,       bos_token_id=snake_case__   ,       eos_token_id=snake_case__	)
         _lowercase     =	hidden_size
         _lowercase     =	feat_extract_norm
         _lowercase     =	feat_extract_activation
         _lowercase     =	list(snake_case__	)
         _lowercase     =	list(snake_case__	)
         _lowercase     =	list(snake_case__	)
         _lowercase     =	conv_bias
         _lowercase     =	num_conv_pos_embeddings
         _lowercase     =	num_conv_pos_embedding_groups
         _lowercase     =	len(self.conv_dim	)
         _lowercase     =	num_hidden_layers
         _lowercase     =	intermediate_size
         _lowercase     =	hidden_act
         _lowercase     =	num_attention_heads
         _lowercase     =	hidden_dropout
         _lowercase     =	attention_dropout
         _lowercase     =	activation_dropout
         _lowercase     =	feat_proj_layer_norm
         _lowercase     =	feat_proj_dropout
         _lowercase     =	final_dropout
         _lowercase     =	layerdrop
         _lowercase     =	layer_norm_eps
         _lowercase     =	initializer_range
         _lowercase     =	vocab_size
         _lowercase     =	do_stable_layer_norm
         _lowercase     =	use_weighted_layer_sum
         _lowercase     =	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
         _lowercase     =	apply_spec_augment
         _lowercase     =	mask_time_prob
         _lowercase     =	mask_time_length
         _lowercase     =	mask_time_min_masks
         _lowercase     =	mask_feature_prob
         _lowercase     =	mask_feature_length
         _lowercase     =	mask_feature_min_masks
  
         # ctc loss
         _lowercase     =	ctc_loss_reduction
         _lowercase     =	ctc_zero_infinity
  
     @property
     def 			SCREAMING_SNAKE_CASE__				(    self:	int	)  ->		Optional[int]:
  
  
         """simple docstring"""
  
  
  
         return functools.reduce(operator.mul   ,       self.conv_stride   ,       1	)
  