


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 MobileViTImageProcessor


class 					lowerCAmelCase_ (       unittest.TestCase):




						def __init__(	self						:   Union[str, Any]   ,     __A						:   Optional[Any]   ,     __A						:   str=7   ,     __A						:   List[Any]=3   ,     __A						:   int=18   ,     __A						:   Optional[Any]=30   ,     __A						:   List[Any]=400   ,     __A						:   Any=True   ,     __A						:   Union[str, Any]=None   ,     __A						:   List[Any]=True   ,     __A						:   Any=None   ,     __A						:   int=True   ,     )      ->Optional[int]:






									"""simple docstring"""






									a__ :str						  =    size if size is not None else {"shortest_edge": 20}
									a__ :Any						  =    crop_size if crop_size is not None else {"height": 18, "width": 18}
									a__ :str						  =    parent
									a__ :int						  =    batch_size
									a__ :List[Any]						  =    num_channels
									a__ :List[str]						  =    image_size
									a__ :Dict						  =    min_resolution
									a__ :str						  =    max_resolution
									a__ :List[Any]						  =    do_resize
									a__ :Any						  =    size
									a__ :Any						  =    do_center_crop
									a__ :Any						  =    crop_size
									a__ :List[str]						  =    do_flip_channel_order






						def  _snake_case					(	self						:   int						)      ->List[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_flip_channel_order": self.do_flip_channel_order,
									}






@require_torch
@require_vision
class 					lowerCAmelCase_ (       _a			,unittest.TestCase):
						lowerCamelCase_         =     MobileViTImageProcessor if is_vision_available() else None




						def  _snake_case					(	self						:   Tuple						)      ->Optional[int]:






									"""simple docstring"""






									a__ :List[Any]						  =    MobileViTImageProcessingTester(self						)




						@property
						def  _snake_case					(	self						:   List[Any]						)      ->Union[str, Any]:






									"""simple docstring"""






									return self.image_processor_tester.prepare_image_processor_dict()




						def  _snake_case					(	self						:   Union[str, Any]						)      ->List[Any]:






									"""simple docstring"""






									a__ :Any						  =    self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(__A   ,     "do_resize"						)						)
									self.assertTrue(hasattr(__A   ,     "size"						)						)
									self.assertTrue(hasattr(__A   ,     "do_center_crop"						)						)
									self.assertTrue(hasattr(__A   ,     "center_crop"						)						)
									self.assertTrue(hasattr(__A   ,     "do_flip_channel_order"						)						)




						def  _snake_case					(	self						:   str						)      ->List[Any]:






									"""simple docstring"""






									a__ :str						  =    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}						)

									a__ :int						  =    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						:   List[Any]						)      ->Tuple:






									"""simple docstring"""






									pass




						def  _snake_case					(	self						:   int						)      ->List[Any]:






									"""simple docstring"""






									a__ :Any						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random PIL images
									a__ :Any						  =    prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=__A						)
									for image in image_inputs:
												self.assertIsInstance(__A   ,     Image.Image						)

									# Test not batched input
									a__ :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
									a__ :str						  =    image_processing(__A   ,     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]						)      ->str:






									"""simple docstring"""






									a__ :Union[str, Any]						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random numpy tensors
									a__ :Dict						  =    prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=__A   ,     numpify=__A						)
									for image in image_inputs:
												self.assertIsInstance(__A   ,     np.ndarray						)

									# Test not batched input
									a__ :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
									a__ :Any						  =    image_processing(__A   ,     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						:   Any						)      ->Dict:






									"""simple docstring"""






									a__ :str						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random PyTorch tensors
									a__ :Union[str, Any]						  =    prepare_image_inputs(self.image_processor_tester   ,     equal_resolution=__A   ,     torchify=__A						)
									for image in image_inputs:
												self.assertIsInstance(__A   ,     torch.Tensor						)

									# Test not batched input
									a__ :Dict						  =    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
									a__ :Optional[int]						  =    image_processing(__A   ,     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


snake_case__			 =						logging.get_logger(__name__)

snake_case__			 =						{
    '''asapp/sew-tiny-100k''': '''https://huggingface.co/asapp/sew-tiny-100k/resolve/main/config.json''',
    # See all SEW models at https://huggingface.co/models?filter=sew
}


class 					lowerCAmelCase_ (       _a):
						lowerCamelCase_         =     'sew'




						def __init__(	self						:   Any   ,     __A						:   str=32   ,     __A						:   Dict=768   ,     __A						:   int=12   ,     __A						:   Dict=12   ,     __A						:   Dict=3072   ,     __A						:   int=2   ,     __A						:   Union[str, Any]="gelu"   ,     __A						:   Union[str, Any]=0.1   ,     __A						:   Optional[Any]=0.1   ,     __A						:   Union[str, Any]=0.1   ,     __A						:   str=0.0   ,     __A						:   Union[str, Any]=0.1   ,     __A						:   Optional[Any]=0.1   ,     __A						:   Tuple=0.02   ,     __A						:   Any=1E-5   ,     __A						:   Optional[Any]="group"   ,     __A						:   str="gelu"   ,     __A						:   Dict=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)   ,     __A						:   Tuple=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)   ,     __A						:   int=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)   ,     __A						:   List[str]=False   ,     __A						:   Tuple=128   ,     __A						:   Tuple=16   ,     __A						:   Optional[int]=True   ,     __A						:   Union[str, Any]=0.05   ,     __A						:   List[str]=10   ,     __A						:   Optional[int]=2   ,     __A						:   List[Any]=0.0   ,     __A						:   Optional[Any]=10   ,     __A						:   Tuple=0   ,     __A						:   Tuple="mean"   ,     __A						:   Any=False   ,     __A						:   str=False   ,     __A						:   Dict=256   ,     __A						:   Union[str, Any]=0   ,     __A						:   Optional[int]=1   ,     __A						:   Optional[Any]=2   ,     **__A						:   Tuple   ,     )      ->Tuple:






									"""simple docstring"""






									super().__init__(**__A   ,     pad_token_id=__A   ,     bos_token_id=__A   ,     eos_token_id=__A						)
									a__ :List[Any]						  =    hidden_size
									a__ :List[Any]						  =    feat_extract_norm
									a__ :List[str]						  =    feat_extract_activation
									a__ :Any						  =    list(__A						)
									a__ :Dict						  =    list(__A						)
									a__ :Optional[int]						  =    list(__A						)
									a__ :Any						  =    conv_bias
									a__ :List[str]						  =    num_conv_pos_embeddings
									a__ :str						  =    num_conv_pos_embedding_groups
									a__ :Optional[int]						  =    len(self.conv_dim						)
									a__ :List[Any]						  =    num_hidden_layers
									a__ :str						  =    intermediate_size
									a__ :Dict						  =    squeeze_factor
									a__ :List[Any]						  =    hidden_act
									a__ :Optional[Any]						  =    num_attention_heads
									a__ :Tuple						  =    hidden_dropout
									a__ :Tuple						  =    attention_dropout
									a__ :List[Any]						  =    activation_dropout
									a__ :str						  =    feat_proj_dropout
									a__ :Any						  =    final_dropout
									a__ :Dict						  =    layerdrop
									a__ :List[str]						  =    layer_norm_eps
									a__ :Tuple						  =    initializer_range
									a__ :Dict						  =    vocab_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)`,"
												    F'''but is `len(config.conv_dim) = {len(self.conv_dim						)}`, `len(config.conv_stride)'''
												    F'''= {len(self.conv_stride						)}`, `len(config.conv_kernel) = {len(self.conv_kernel						)}`.'''						)

									# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
									a__ :int						  =    apply_spec_augment
									a__ :Optional[Any]						  =    mask_time_prob
									a__ :List[Any]						  =    mask_time_length
									a__ :Any						  =    mask_time_min_masks
									a__ :Any						  =    mask_feature_prob
									a__ :Dict						  =    mask_feature_length
									a__ :Union[str, Any]						  =    mask_feature_min_masks

									# ctc loss
									a__ :Dict						  =    ctc_loss_reduction
									a__ :Any						  =    ctc_zero_infinity

									# sequence classification
									a__ :Optional[int]						  =    use_weighted_layer_sum
									a__ :Tuple						  =    classifier_proj_size






						@property
						def  _snake_case					(	self						:   Dict						)      ->Union[str, Any]:






									"""simple docstring"""






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


