



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_video_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import VivitImageProcessor

class        UpperCAmelCase_  (       unittest.TestCase	):

						'''simple docstring'''




						def __init__(   self				,							_A				,							_A=7				,							_A=3				,							_A=10				,							_A=18				,							_A=30				,							_A=400				,							_A=True				,							_A=None				,							_A=True				,							_A=[0.5, 0.5, 0.5]				,							_A=[0.5, 0.5, 0.5]				,							_A=None				,							):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= size if size is not None else {'shortest_edge': 18}
													__SCREAMING_SNAKE_CASE									= crop_size if crop_size is not None else {'height': 18, 'width': 18}

													__SCREAMING_SNAKE_CASE									= parent
													__SCREAMING_SNAKE_CASE									= batch_size
													__SCREAMING_SNAKE_CASE									= num_channels
													__SCREAMING_SNAKE_CASE									= num_frames
													__SCREAMING_SNAKE_CASE									= image_size
													__SCREAMING_SNAKE_CASE									= min_resolution
													__SCREAMING_SNAKE_CASE									= max_resolution
													__SCREAMING_SNAKE_CASE									= do_resize
													__SCREAMING_SNAKE_CASE									= size
													__SCREAMING_SNAKE_CASE									= do_normalize
													__SCREAMING_SNAKE_CASE									= image_mean
													__SCREAMING_SNAKE_CASE									= image_std
													__SCREAMING_SNAKE_CASE									= crop_size






						def 	_A     (   self		):







													'''simple docstring'''

													return {
													    "image_mean": self.image_mean,
													    "image_std": self.image_std,
													    "do_normalize": self.do_normalize,
													    "do_resize": self.do_resize,
													    "size": self.size,
													    "crop_size": self.crop_size,
													}







@require_torch
@require_vision
class        UpperCAmelCase_  (       UpperCamelCase_   ,   unittest.TestCase	):

						'''simple docstring'''




						UpperCamelCase__      :			Any      =  VivitImageProcessor if is_vision_available() else None






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= VivitImageProcessingTester(self		)






						@property
						def 	_A     (   self		):







													'''simple docstring'''

													return self.image_processor_tester.prepare_image_processor_dict()






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.image_processing_class(**self.image_processor_dict		)
													self.assertTrue(hasattr(_A				,							'image_mean'		)		)
													self.assertTrue(hasattr(_A				,							'image_std'		)		)
													self.assertTrue(hasattr(_A				,							'do_normalize'		)		)
													self.assertTrue(hasattr(_A				,							'do_resize'		)		)
													self.assertTrue(hasattr(_A				,							'do_center_crop'		)		)
													self.assertTrue(hasattr(_A				,							'size'		)		)






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.image_processing_class.from_dict(self.image_processor_dict		)
													self.assertEqual(image_processor.size				,							{'shortest_edge': 18}		)
													self.assertEqual(image_processor.crop_size				,							{'height': 18, 'width': 18}		)

													__SCREAMING_SNAKE_CASE									= 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 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.image_processing_class(**self.image_processor_dict		)
													# create random PIL videos
													__SCREAMING_SNAKE_CASE									= prepare_video_inputs(self.image_processor_tester				,							equal_resolution=_A		)
													for video in video_inputs:
																				self.assertIsInstance(_A				,							_A		)
																				self.assertIsInstance(video[0]				,							Image.Image		)

													# Test not batched input
													__SCREAMING_SNAKE_CASE									= image_processing(video_inputs[0]				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        1,
													        self.image_processor_tester.num_frames,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.crop_size['height'],
													        self.image_processor_tester.crop_size['width'],
													    )				,							)

													# Test batched
													__SCREAMING_SNAKE_CASE									= image_processing(_A				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_frames,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.crop_size['height'],
													        self.image_processor_tester.crop_size['width'],
													    )				,							)






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.image_processing_class(**self.image_processor_dict		)
													# create random numpy tensors
													__SCREAMING_SNAKE_CASE									= prepare_video_inputs(self.image_processor_tester				,							equal_resolution=_A				,							numpify=_A		)
													for video in video_inputs:
																				self.assertIsInstance(_A				,							_A		)
																				self.assertIsInstance(video[0]				,							np.ndarray		)

													# Test not batched input
													__SCREAMING_SNAKE_CASE									= image_processing(video_inputs[0]				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        1,
													        self.image_processor_tester.num_frames,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.crop_size['height'],
													        self.image_processor_tester.crop_size['width'],
													    )				,							)

													# Test batched
													__SCREAMING_SNAKE_CASE									= image_processing(_A				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_frames,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.crop_size['height'],
													        self.image_processor_tester.crop_size['width'],
													    )				,							)






						def 	_A     (   self		):







													'''simple docstring'''

													__SCREAMING_SNAKE_CASE									= self.image_processing_class(**self.image_processor_dict		)
													# create random PyTorch tensors
													__SCREAMING_SNAKE_CASE									= prepare_video_inputs(self.image_processor_tester				,							equal_resolution=_A				,							torchify=_A		)
													for video in video_inputs:
																				self.assertIsInstance(_A				,							_A		)
																				self.assertIsInstance(video[0]				,							torch.Tensor		)

													# Test not batched input
													__SCREAMING_SNAKE_CASE									= image_processing(video_inputs[0]				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        1,
													        self.image_processor_tester.num_frames,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.crop_size['height'],
													        self.image_processor_tester.crop_size['width'],
													    )				,							)

													# Test batched
													__SCREAMING_SNAKE_CASE									= image_processing(_A				,							return_tensors='pt'		).pixel_values
													self.assertEqual(
													    encoded_videos.shape				,							(
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.num_frames,
													        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__		:					Dict							=logging.get_logger(__name__)

lowerCAmelCase__		:					Optional[int]							={
    '''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        UpperCAmelCase_  (       UpperCamelCase_	):

						'''simple docstring'''




						UpperCamelCase__      :			Optional[Any]      =  '''sew'''






						def __init__(   self				,							_A=32				,							_A=768				,							_A=12				,							_A=12				,							_A=3_072				,							_A=2				,							_A="gelu"				,							_A=0.1				,							_A=0.1				,							_A=0.1				,							_A=0.0				,							_A=0.1				,							_A=0.1				,							_A=0.0_2				,							_A=1e-5				,							_A="group"				,							_A="gelu"				,							_A=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)				,							_A=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)				,							_A=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)				,							_A=False				,							_A=128				,							_A=16				,							_A=True				,							_A=0.0_5				,							_A=10				,							_A=2				,							_A=0.0				,							_A=10				,							_A=0				,							_A="mean"				,							_A=False				,							_A=False				,							_A=256				,							_A=0				,							_A=1				,							_A=2				,							**_A				,							):







													'''simple docstring'''

													super().__init__(**_A				,							pad_token_id=_A				,							bos_token_id=_A				,							eos_token_id=_A		)
													__SCREAMING_SNAKE_CASE									= hidden_size
													__SCREAMING_SNAKE_CASE									= feat_extract_norm
													__SCREAMING_SNAKE_CASE									= feat_extract_activation
													__SCREAMING_SNAKE_CASE									= list(_A		)
													__SCREAMING_SNAKE_CASE									= list(_A		)
													__SCREAMING_SNAKE_CASE									= list(_A		)
													__SCREAMING_SNAKE_CASE									= conv_bias
													__SCREAMING_SNAKE_CASE									= num_conv_pos_embeddings
													__SCREAMING_SNAKE_CASE									= num_conv_pos_embedding_groups
													__SCREAMING_SNAKE_CASE									= len(self.conv_dim		)
													__SCREAMING_SNAKE_CASE									= num_hidden_layers
													__SCREAMING_SNAKE_CASE									= intermediate_size
													__SCREAMING_SNAKE_CASE									= squeeze_factor
													__SCREAMING_SNAKE_CASE									= hidden_act
													__SCREAMING_SNAKE_CASE									= num_attention_heads
													__SCREAMING_SNAKE_CASE									= hidden_dropout
													__SCREAMING_SNAKE_CASE									= attention_dropout
													__SCREAMING_SNAKE_CASE									= activation_dropout
													__SCREAMING_SNAKE_CASE									= feat_proj_dropout
													__SCREAMING_SNAKE_CASE									= final_dropout
													__SCREAMING_SNAKE_CASE									= layerdrop
													__SCREAMING_SNAKE_CASE									= layer_norm_eps
													__SCREAMING_SNAKE_CASE									= initializer_range
													__SCREAMING_SNAKE_CASE									= 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
													__SCREAMING_SNAKE_CASE									= apply_spec_augment
													__SCREAMING_SNAKE_CASE									= mask_time_prob
													__SCREAMING_SNAKE_CASE									= mask_time_length
													__SCREAMING_SNAKE_CASE									= mask_time_min_masks
													__SCREAMING_SNAKE_CASE									= mask_feature_prob
													__SCREAMING_SNAKE_CASE									= mask_feature_length
													__SCREAMING_SNAKE_CASE									= mask_feature_min_masks

													# ctc loss
													__SCREAMING_SNAKE_CASE									= ctc_loss_reduction
													__SCREAMING_SNAKE_CASE									= ctc_zero_infinity

													# sequence classification
													__SCREAMING_SNAKE_CASE									= use_weighted_layer_sum
													__SCREAMING_SNAKE_CASE									= classifier_proj_size






						@property
						def 	_A     (   self		):







													'''simple docstring'''

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






