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 OwlViTImageProcessor







class      SCREAMING_SNAKE_CASE__					(  unittest.TestCase    ):

       def __init__(							self					:     List[str]			,			_lowerCAmelCase					:     str			,			_lowerCAmelCase					:     Optional[int]=7			,			_lowerCAmelCase					:     Tuple=3			,			_lowerCAmelCase					:     int=18			,			_lowerCAmelCase					:     List[Any]=30			,			_lowerCAmelCase					:     int=4_00			,			_lowerCAmelCase					:     Optional[Any]=True			,			_lowerCAmelCase					:     str=None			,			_lowerCAmelCase					:     int=True			,			_lowerCAmelCase					:     int=None			,			_lowerCAmelCase					:     str=True			,			_lowerCAmelCase					:     Dict=[0.48145466, 0.4578275, 0.40821073]			,			_lowerCAmelCase					:     List[Any]=[0.26862954, 0.26130258, 0.27577711]			,			_lowerCAmelCase					:     int=True			,			):
           __snake_case       :				Union[str, Any] 			=    parent
           __snake_case       :				str 			=    batch_size
           __snake_case       :				Optional[Any] 			=    num_channels
           __snake_case       :				Tuple 			=    image_size
           __snake_case       :				List[Any] 			=    min_resolution
           __snake_case       :				Any 			=    max_resolution
           __snake_case       :				Tuple 			=    do_resize
           __snake_case       :				str 			=    size if size is not None else {"""height""": 18, """width""": 18}
           __snake_case       :				List[Any] 			=    do_center_crop
           __snake_case       :				Union[str, Any] 			=    crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
           __snake_case       :				List[Any] 			=    do_normalize
           __snake_case       :				Union[str, Any] 			=    image_mean
           __snake_case       :				Optional[Any] 			=    image_std
           __snake_case       :				int 			=    do_convert_rgb





       def 			snake_case__    (							self					:     List[Any]			):
           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,
           }







@require_torch
@require_vision
class      SCREAMING_SNAKE_CASE__					(  __UpperCamelCase   ,							unittest.TestCase    ):
       A							:	int          =	OwlViTImageProcessor if is_vision_available() else None

       def 			snake_case__    (							self					:     Dict			):
           __snake_case       :				Optional[Any] 			=    OwlViTImageProcessingTester(self			)

       @property
       def 			snake_case__    (							self					:     Union[str, Any]			):
           return self.image_processor_tester.prepare_image_processor_dict()

       def 			snake_case__    (							self					:     Dict			):
           __snake_case       :				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_normalize"""			)			)
           self.assertTrue(hasattr(_lowerCAmelCase			,			"""image_mean"""			)			)
           self.assertTrue(hasattr(_lowerCAmelCase			,			"""image_std"""			)			)
           self.assertTrue(hasattr(_lowerCAmelCase			,			"""do_convert_rgb"""			)			)

       def 			snake_case__    (							self					:     int			):
           __snake_case       :				Optional[int] 			=    self.image_processing_class.from_dict(self.image_processor_dict			)
           self.assertEqual(image_processor.size			,			{"""height""": 18, """width""": 18}			)
           self.assertEqual(image_processor.crop_size			,			{"""height""": 18, """width""": 18}			)

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

       def 			snake_case__    (							self					:     Union[str, Any]			):
           # Initialize image_processing
           __snake_case       :				int 			=    self.image_processing_class(**self.image_processor_dict			)
           # create random PIL images
           __snake_case       :				str 			=    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       :				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
           __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.crop_size["""height"""],
                   self.image_processor_tester.crop_size["""width"""],
               )			,			)

       def 			snake_case__    (							self					:     List[Any]			):
           # Initialize image_processing
           __snake_case       :				Tuple 			=    self.image_processing_class(**self.image_processor_dict			)
           # create random numpy tensors
           __snake_case       :				int 			=    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       :				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
           __snake_case       :				Dict 			=    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 			snake_case__    (							self					:     Optional[Any]			):
           # Initialize image_processing
           __snake_case       :				Optional[Any] 			=    self.image_processing_class(**self.image_processor_dict			)
           # create random PyTorch tensors
           __snake_case       :				Union[str, 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
           __snake_case       :				Union[str, 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
           __snake_case       :				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"""],
               )			,			)




import functools
import operator

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


lowercase_  							=			logging.get_logger(__name__)

lowercase_  							=			{
    "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      SCREAMING_SNAKE_CASE__					(  __UpperCamelCase    ):
       A							:	List[str]          =	"hubert"

       def __init__(							self					:     List[str]			,			_lowerCAmelCase					:     Union[str, Any]=32			,			_lowerCAmelCase					:     Any=7_68			,			_lowerCAmelCase					:     Optional[Any]=12			,			_lowerCAmelCase					:     Optional[int]=12			,			_lowerCAmelCase					:     int=30_72			,			_lowerCAmelCase					:     Optional[Any]="gelu"			,			_lowerCAmelCase					:     List[str]=0.1			,			_lowerCAmelCase					:     Any=0.1			,			_lowerCAmelCase					:     List[str]=0.1			,			_lowerCAmelCase					:     Dict=True			,			_lowerCAmelCase					:     Dict=0.0			,			_lowerCAmelCase					:     List[str]=0.1			,			_lowerCAmelCase					:     Optional[int]=0.1			,			_lowerCAmelCase					:     Dict=0.02			,			_lowerCAmelCase					:     Any=1e-5			,			_lowerCAmelCase					:     str="group"			,			_lowerCAmelCase					:     Any="gelu"			,			_lowerCAmelCase					:     List[str]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)			,			_lowerCAmelCase					:     Any=(5, 2, 2, 2, 2, 2, 2)			,			_lowerCAmelCase					:     Dict=(10, 3, 3, 3, 3, 2, 2)			,			_lowerCAmelCase					:     List[str]=False			,			_lowerCAmelCase					:     Optional[Any]=1_28			,			_lowerCAmelCase					:     int=16			,			_lowerCAmelCase					:     Tuple=False			,			_lowerCAmelCase					:     int=True			,			_lowerCAmelCase					:     int=0.05			,			_lowerCAmelCase					:     Any=10			,			_lowerCAmelCase					:     Dict=2			,			_lowerCAmelCase					:     Dict=0.0			,			_lowerCAmelCase					:     Optional[int]=10			,			_lowerCAmelCase					:     Union[str, Any]=0			,			_lowerCAmelCase					:     int="sum"			,			_lowerCAmelCase					:     Optional[int]=False			,			_lowerCAmelCase					:     str=False			,			_lowerCAmelCase					:     Optional[Any]=2_56			,			_lowerCAmelCase					:     Any=0			,			_lowerCAmelCase					:     List[Any]=1			,			_lowerCAmelCase					:     List[str]=2			,			**_lowerCAmelCase					:     Optional[int]			,			):
           super().__init__(**_lowerCAmelCase			,			pad_token_id=_lowerCAmelCase			,			bos_token_id=_lowerCAmelCase			,			eos_token_id=_lowerCAmelCase			)
           __snake_case       :				Optional[int] 			=    hidden_size
           __snake_case       :				Optional[Any] 			=    feat_extract_norm
           __snake_case       :				Optional[int] 			=    feat_extract_activation
           __snake_case       :				List[str] 			=    list(_lowerCAmelCase			)
           __snake_case       :				Any 			=    list(_lowerCAmelCase			)
           __snake_case       :				List[Any] 			=    list(_lowerCAmelCase			)
           __snake_case       :				Any 			=    conv_bias
           __snake_case       :				Tuple 			=    num_conv_pos_embeddings
           __snake_case       :				List[Any] 			=    num_conv_pos_embedding_groups
           __snake_case       :				Union[str, Any] 			=    len(self.conv_dim			)
           __snake_case       :				List[Any] 			=    num_hidden_layers
           __snake_case       :				Tuple 			=    intermediate_size
           __snake_case       :				Optional[int] 			=    hidden_act
           __snake_case       :				Union[str, Any] 			=    num_attention_heads
           __snake_case       :				str 			=    hidden_dropout
           __snake_case       :				Union[str, Any] 			=    attention_dropout
           __snake_case       :				Dict 			=    activation_dropout
           __snake_case       :				List[Any] 			=    feat_proj_layer_norm
           __snake_case       :				List[str] 			=    feat_proj_dropout
           __snake_case       :				List[Any] 			=    final_dropout
           __snake_case       :				str 			=    layerdrop
           __snake_case       :				List[str] 			=    layer_norm_eps
           __snake_case       :				Optional[Any] 			=    initializer_range
           __snake_case       :				Optional[int] 			=    vocab_size
           __snake_case       :				Dict 			=    do_stable_layer_norm
           __snake_case       :				Tuple 			=    use_weighted_layer_sum
           __snake_case       :				List[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
           __snake_case       :				Union[str, Any] 			=    apply_spec_augment
           __snake_case       :				List[str] 			=    mask_time_prob
           __snake_case       :				Dict 			=    mask_time_length
           __snake_case       :				int 			=    mask_time_min_masks
           __snake_case       :				List[str] 			=    mask_feature_prob
           __snake_case       :				Tuple 			=    mask_feature_length
           __snake_case       :				int 			=    mask_feature_min_masks

           # ctc loss
           __snake_case       :				Dict 			=    ctc_loss_reduction
           __snake_case       :				List[str] 			=    ctc_zero_infinity





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



