


'''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 ViTImageProcessor







class 					_A						(						unittest.TestCase							):



   '''simple docstring'''






   def __init__(	self	:					Any					, lowerCamelCase	:					Any					, lowerCamelCase	:					Tuple=7					, lowerCamelCase	:					Any=3					, lowerCamelCase	:					Tuple=18					, lowerCamelCase	:					Union[str, Any]=30					, lowerCamelCase	:					Dict=400					, lowerCamelCase	:					Dict=True					, lowerCamelCase	:					Union[str, Any]=None					, lowerCamelCase	:					Optional[int]=True					, lowerCamelCase	:					Union[str, Any]=[0.5, 0.5, 0.5]					, lowerCamelCase	:					List[str]=[0.5, 0.5, 0.5]					, )->	List[str]:
          snake_case__					:	Dict          =					size if size is not None else {"""height""": 18, """width""": 18}
          snake_case__					:	Optional[int]          =					parent
          snake_case__					:	str          =					batch_size
          snake_case__					:	Any          =					num_channels
          snake_case__					:	Union[str, Any]          =					image_size
          snake_case__					:	int          =					min_resolution
          snake_case__					:	Any          =					max_resolution
          snake_case__					:	Dict          =					do_resize
          snake_case__					:	Optional[int]          =					size
          snake_case__					:	Any          =					do_normalize
          snake_case__					:	List[str]          =					image_mean
          snake_case__					:	str          =					image_std




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Union[str, Any]:
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
          }







@require_torch
@require_vision
class 					_A						(						snake_case__    ,  unittest.TestCase							):



   '''simple docstring'''






   _lowercase    						= ViTImageProcessor if is_vision_available() else None




   def   __lowerCAmelCase						(	self	:					str						)->	Optional[int]:
          snake_case__					:	Tuple          =					ViTImageProcessingTester(self						)




   @property
   def   __lowerCAmelCase						(	self	:					List[str]						)->	Optional[Any]:
          return self.image_processor_tester.prepare_image_processor_dict()




   def   __lowerCAmelCase						(	self	:					str						)->	int:
          snake_case__					:	Tuple          =					self.image_processing_class(**self.image_processor_dict						)
          self.assertTrue(hasattr(__lowerCAmelCase					, """image_mean"""						)						)
          self.assertTrue(hasattr(__lowerCAmelCase					, """image_std"""						)						)
          self.assertTrue(hasattr(__lowerCAmelCase					, """do_normalize"""						)						)
          self.assertTrue(hasattr(__lowerCAmelCase					, """do_resize"""						)						)
          self.assertTrue(hasattr(__lowerCAmelCase					, """size"""						)						)




   def   __lowerCAmelCase						(	self	:					Dict						)->	List[str]:
          snake_case__					:	Tuple          =					self.image_processing_class.from_dict(self.image_processor_dict						)
          self.assertEqual(image_processor.size					, {"""height""": 18, """width""": 18}						)

          snake_case__					:	Dict          =					self.image_processing_class.from_dict(self.image_processor_dict					, size=42						)
          self.assertEqual(image_processor.size					, {"""height""": 42, """width""": 42}						)




   def   __lowerCAmelCase						(	self	:					str						)->	List[str]:
          pass




   def   __lowerCAmelCase						(	self	:					List[str]						)->	Union[str, Any]:
          snake_case__					:	Optional[Any]          =					self.image_processing_class(**self.image_processor_dict						)
          # create random PIL images
          snake_case__					:	List[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
          snake_case__					:	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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )

          # Test batched
          snake_case__					:	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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Optional[Any]:
          snake_case__					:	Tuple          =					self.image_processing_class(**self.image_processor_dict						)
          # create random numpy tensors
          snake_case__					:	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
          snake_case__					:	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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )

          # Test batched
          snake_case__					:	Optional[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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )




   def   __lowerCAmelCase						(	self	:					Optional[int]						)->	Optional[Any]:
          snake_case__					:	Optional[Any]          =					self.image_processing_class(**self.image_processor_dict						)
          # create random PyTorch tensors
          snake_case__					:	Tuple          =					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
          snake_case__					:	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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )

          # Test batched
          snake_case__					:	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.size["""height"""],
                  self.image_processor_tester.size["""width"""],
              )					, )










'''simple docstring'''





import functools
import operator

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


a		:	Dict       =      logging.get_logger(__name__)

a		:	Optional[int]       =      {
    '''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       (	snake_case__       ):
  a     :int          =					'hubert'



  def __init__(			self		,     __lowerCAmelCase=32		,     __lowerCAmelCase=768		,     __lowerCAmelCase=12		,     __lowerCAmelCase=12		,     __lowerCAmelCase=3072		,     __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		,     ):







      '''simple docstring'''


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

      # ctc loss
      _a				:							Tuple							       =      ctc_loss_reduction
      _a				:							Optional[int]							       =      ctc_zero_infinity



  @property
  def     a_							(			self ):







      '''simple docstring'''


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


