





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





class lowerCamelCase						(unittest.TestCase					):







  def __init__(		self     ,     lowercase__     ,     lowercase__=7     ,     lowercase__=3     ,     lowercase__=18     ,     lowercase__=30     ,     lowercase__=400     ,     lowercase__=True     ,     lowercase__=None     ,     lowercase__=True     ,     lowercase__=None     ,     lowercase__=True     ,     lowercase__=[0.5, 0.5, 0.5]     ,     lowercase__=[0.5, 0.5, 0.5]     ,     )		->						List[Any]:






        """simple docstring"""





        _snake_case		:	int					     =     size if size is not None else {'''shortest_edge''': 18}
        _snake_case		:	Tuple					     =     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
        _snake_case		:	Union[str, Any]					     =     parent
        _snake_case		:	List[str]					     =     batch_size
        _snake_case		:	Optional[Any]					     =     num_channels
        _snake_case		:	Any					     =     image_size
        _snake_case		:	Union[str, Any]					     =     min_resolution
        _snake_case		:	Optional[Any]					     =     max_resolution
        _snake_case		:	Any					     =     do_resize
        _snake_case		:	Union[str, Any]					     =     size
        _snake_case		:	Optional[int]					     =     do_center_crop
        _snake_case		:	Tuple					     =     crop_size
        _snake_case		:	List[Any]					     =     do_normalize
        _snake_case		:	Dict					     =     image_mean
        _snake_case		:	str					     =     image_std







  def 				UpperCAmelCase_				(		self		)		->						Dict:






        """simple docstring"""





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





@require_torch
@require_vision
class lowerCamelCase						(a__						,      unittest.TestCase					):
  _lowercase  :	Tuple       					=				LevitImageProcessor if is_vision_available() else None







  def 				UpperCAmelCase_				(		self		)		->						List[str]:






        """simple docstring"""





        _snake_case		:	int					     =     LevitImageProcessingTester(self		)







  @property
  def 				UpperCAmelCase_				(		self		)		->						List[str]:






        """simple docstring"""





        return self.image_processor_tester.prepare_image_processor_dict()







  def 				UpperCAmelCase_				(		self		)		->						Tuple:






        """simple docstring"""





        _snake_case		:	Tuple					     =     self.image_processing_class(**self.image_processor_dict		)
        self.assertTrue(hasattr(lowercase__     ,     '''image_mean'''		)		)
        self.assertTrue(hasattr(lowercase__     ,     '''image_std'''		)		)
        self.assertTrue(hasattr(lowercase__     ,     '''do_normalize'''		)		)
        self.assertTrue(hasattr(lowercase__     ,     '''do_resize'''		)		)
        self.assertTrue(hasattr(lowercase__     ,     '''do_center_crop'''		)		)
        self.assertTrue(hasattr(lowercase__     ,     '''size'''		)		)







  def 				UpperCAmelCase_				(		self		)		->						Optional[Any]:






        """simple docstring"""





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

        _snake_case		:	Tuple					     =     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 				UpperCAmelCase_				(		self		)		->						Tuple:






        """simple docstring"""





        pass







  def 				UpperCAmelCase_				(		self		)		->						Optional[int]:






        """simple docstring"""





        _snake_case		:	Dict					     =     self.image_processing_class(**self.image_processor_dict		)
        # create random PIL images
        _snake_case		:	Optional[Any]					     =     prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=lowercase__		)
        for image in image_inputs:
              self.assertIsInstance(lowercase__     ,     Image.Image		)

        # Test not batched input
        _snake_case		:	List[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
        _snake_case		:	Any					     =     image_processing(lowercase__     ,     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 				UpperCAmelCase_				(		self		)		->						List[Any]:






        """simple docstring"""





        _snake_case		:	List[str]					     =     self.image_processing_class(**self.image_processor_dict		)
        # create random numpy tensors
        _snake_case		:	Optional[int]					     =     prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=lowercase__     ,     numpify=lowercase__		)
        for image in image_inputs:
              self.assertIsInstance(lowercase__     ,     np.ndarray		)

        # 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(lowercase__     ,     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 				UpperCAmelCase_				(		self		)		->						Optional[Any]:






        """simple docstring"""





        _snake_case		:	Dict					     =     self.image_processing_class(**self.image_processor_dict		)
        # create random PyTorch tensors
        _snake_case		:	str					     =     prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=lowercase__     ,     torchify=lowercase__		)
        for image in image_inputs:
              self.assertIsInstance(lowercase__     ,     torch.Tensor		)

        # Test not batched input
        _snake_case		:	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
        _snake_case		:	Dict					     =     image_processing(lowercase__     ,     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'''],
            )     ,     )









'''simple docstring'''

import functools
import operator

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


UpperCAmelCase					:		List[str]		=							logging.get_logger(__name__)

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





class lowerCamelCase						(a__					):
  _lowercase  :	List[str]       					=				"""sew-d"""







  def __init__(		self     ,     lowercase__=32     ,     lowercase__=768     ,     lowercase__=12     ,     lowercase__=12     ,     lowercase__=3_072     ,     lowercase__=2     ,     lowercase__=512     ,     lowercase__=256     ,     lowercase__=True     ,     lowercase__=True     ,     lowercase__=("p2c", "c2p")     ,     lowercase__="layer_norm"     ,     lowercase__="gelu_python"     ,     lowercase__=0.1     ,     lowercase__=0.1     ,     lowercase__=0.1     ,     lowercase__=0.0     ,     lowercase__=0.1     ,     lowercase__=0.02     ,     lowercase__=1E-7     ,     lowercase__=1E-5     ,     lowercase__="group"     ,     lowercase__="gelu"     ,     lowercase__=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)     ,     lowercase__=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)     ,     lowercase__=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)     ,     lowercase__=False     ,     lowercase__=128     ,     lowercase__=16     ,     lowercase__=True     ,     lowercase__=0.05     ,     lowercase__=10     ,     lowercase__=2     ,     lowercase__=0.0     ,     lowercase__=10     ,     lowercase__=0     ,     lowercase__="mean"     ,     lowercase__=False     ,     lowercase__=False     ,     lowercase__=256     ,     lowercase__=0     ,     lowercase__=1     ,     lowercase__=2     ,     **lowercase__     ,     )		->						Dict:






        """simple docstring"""





        super().__init__(**lowercase__     ,     pad_token_id=lowercase__     ,     bos_token_id=lowercase__     ,     eos_token_id=lowercase__		)
        _snake_case		:	List[str]					     =     hidden_size
        _snake_case		:	Optional[Any]					     =     feat_extract_norm
        _snake_case		:	Tuple					     =     feat_extract_activation
        _snake_case		:	Tuple					     =     list(lowercase__		)
        _snake_case		:	Any					     =     list(lowercase__		)
        _snake_case		:	Any					     =     list(lowercase__		)
        _snake_case		:	Any					     =     conv_bias
        _snake_case		:	List[Any]					     =     num_conv_pos_embeddings
        _snake_case		:	Any					     =     num_conv_pos_embedding_groups
        _snake_case		:	Union[str, Any]					     =     len(self.conv_dim		)
        _snake_case		:	Optional[Any]					     =     num_hidden_layers
        _snake_case		:	Optional[int]					     =     intermediate_size
        _snake_case		:	Any					     =     squeeze_factor
        _snake_case		:	Optional[Any]					     =     max_position_embeddings
        _snake_case		:	Tuple					     =     position_buckets
        _snake_case		:	Tuple					     =     share_att_key
        _snake_case		:	Any					     =     relative_attention
        _snake_case		:	Optional[int]					     =     norm_rel_ebd
        _snake_case		:	Optional[Any]					     =     list(lowercase__		)
        _snake_case		:	List[Any]					     =     hidden_act
        _snake_case		:	List[Any]					     =     num_attention_heads
        _snake_case		:	Dict					     =     hidden_dropout
        _snake_case		:	Tuple					     =     attention_dropout
        _snake_case		:	Union[str, Any]					     =     activation_dropout
        _snake_case		:	List[Any]					     =     feat_proj_dropout
        _snake_case		:	Optional[int]					     =     final_dropout
        _snake_case		:	Optional[Any]					     =     layer_norm_eps
        _snake_case		:	Dict					     =     feature_layer_norm_eps
        _snake_case		:	List[Any]					     =     initializer_range
        _snake_case		:	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
        _snake_case		:	Union[str, Any]					     =     apply_spec_augment
        _snake_case		:	Any					     =     mask_time_prob
        _snake_case		:	List[str]					     =     mask_time_length
        _snake_case		:	Dict					     =     mask_time_min_masks
        _snake_case		:	Union[str, Any]					     =     mask_feature_prob
        _snake_case		:	Tuple					     =     mask_feature_length
        _snake_case		:	Union[str, Any]					     =     mask_feature_min_masks

        # ctc loss
        _snake_case		:	Optional[Any]					     =     ctc_loss_reduction
        _snake_case		:	Optional[Any]					     =     ctc_zero_infinity

        # sequence classification
        _snake_case		:	List[Any]					     =     use_weighted_layer_sum
        _snake_case		:	Any					     =     classifier_proj_size







  @property
  def 				UpperCAmelCase_				(		self		)		->						Any:






        """simple docstring"""





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


