


import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor





class  lowerCAmelCase__(    unittest.TestCase						):






    '''simple docstring'''





    def __init__(	self				:   str       ,   __snake_case				:   int       ,   __snake_case				:   Dict=7       ,   __snake_case				:   Any=3       ,   __snake_case				:   Dict=18       ,   __snake_case				:   Optional[Any]=30       ,   __snake_case				:   Tuple=400       ,   __snake_case				:   List[str]=True       ,   __snake_case				:   Tuple=None       ,   __snake_case				:   Tuple=True       ,   __snake_case				:   Dict=False       ,   __snake_case				:   Any=True       ,   __snake_case				:   Optional[Any]=True       ,   __snake_case				:   Dict=[0.5, 0.5, 0.5]       ,   __snake_case				:   int=[0.5, 0.5, 0.5]       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   parent
       UpperCAmelCase_							:      List[str]						=   batch_size
       UpperCAmelCase_							:      str						=   num_channels
       UpperCAmelCase_							:      Union[str, Any]						=   image_size
       UpperCAmelCase_							:      Optional[Any]						=   min_resolution
       UpperCAmelCase_							:      Union[str, Any]						=   max_resolution
       UpperCAmelCase_							:      Dict						=   do_resize
       UpperCAmelCase_							:      Optional[Any]						=   size if size is not None else {'''height''': 18, '''width''': 20}
       UpperCAmelCase_							:      Dict						=   do_thumbnail
       UpperCAmelCase_							:      int						=   do_align_axis
       UpperCAmelCase_							:      Dict						=   do_pad
       UpperCAmelCase_							:      Optional[int]						=   do_normalize
       UpperCAmelCase_							:      List[str]						=   image_mean
       UpperCAmelCase_							:      Any						=   image_std





    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       return {
           "do_resize": self.do_resize,
           "size": self.size,
           "do_thumbnail": self.do_thumbnail,
           "do_align_long_axis": self.do_align_axis,
           "do_pad": self.do_pad,
           "do_normalize": self.do_normalize,
           "image_mean": self.image_mean,
           "image_std": self.image_std,
       }





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






    '''simple docstring'''





    A_  :     str			= DonutImageProcessor if is_vision_available() else None





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   DonutImageProcessingTester(self	)





    @property
    def 					_lowerCamelCase (	self				:   Optional[int]	):





       '''simple docstring'''
       return self.image_processor_tester.prepare_image_processor_dict()





    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   self.image_processing_class(**self.image_processor_dict	)
       self.assertTrue(hasattr(__snake_case       ,   '''do_resize'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''size'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''do_thumbnail'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''do_align_long_axis'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''do_pad'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''do_normalize'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''image_mean'''	)	)
       self.assertTrue(hasattr(__snake_case       ,   '''image_std'''	)	)





    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   self.image_processing_class.from_dict(self.image_processor_dict	)
       self.assertEqual(image_processor.size       ,   {'''height''': 18, '''width''': 20}	)

       UpperCAmelCase_							:      int						=   self.image_processing_class.from_dict(self.image_processor_dict       ,   size=42	)
       self.assertEqual(image_processor.size       ,   {'''height''': 42, '''width''': 42}	)

       # Previous config had dimensions in (width, height) order
       UpperCAmelCase_							:      Tuple						=   self.image_processing_class.from_dict(self.image_processor_dict       ,   size=(42, 84)	)
       self.assertEqual(image_processor.size       ,   {'''height''': 84, '''width''': 42}	)





    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       pass





    @is_flaky()
    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Union[str, Any]						=   self.image_processing_class(**self.image_processor_dict	)
       # create random PIL images
       UpperCAmelCase_							:      str						=   prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case	)
       for image in image_inputs:
          self.assertIsInstance(__snake_case       ,   Image.Image	)

       # Test not batched input
       UpperCAmelCase_							:      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
       UpperCAmelCase_							:      Optional[Any]						=   image_processing(__snake_case       ,   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'''],
           )       ,   )





    @is_flaky()
    def 					_lowerCamelCase (	self				:   Union[str, Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      str						=   self.image_processing_class(**self.image_processor_dict	)
       # create random numpy tensors
       UpperCAmelCase_							:      Any						=   prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case       ,   numpify=__snake_case	)
       for image in image_inputs:
          self.assertIsInstance(__snake_case       ,   np.ndarray	)

       # Test not batched input
       UpperCAmelCase_							:      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.size['''height'''],
               self.image_processor_tester.size['''width'''],
           )       ,   )

       # Test batched
       UpperCAmelCase_							:      str						=   image_processing(__snake_case       ,   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'''],
           )       ,   )





    @is_flaky()
    def 					_lowerCamelCase (	self				:   str	):





       '''simple docstring'''
       UpperCAmelCase_							:      Tuple						=   self.image_processing_class(**self.image_processor_dict	)
       # create random PyTorch tensors
       UpperCAmelCase_							:      List[str]						=   prepare_image_inputs(self.image_processor_tester       ,   equal_resolution=__snake_case       ,   torchify=__snake_case	)
       for image in image_inputs:
          self.assertIsInstance(__snake_case       ,   torch.Tensor	)

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



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


__UpperCamelCase				:  int      					=							logging.get_logger(__name__)

__UpperCamelCase				:  Union[str, Any]      					=							{
    'facebook/timesformer': 'https://huggingface.co/facebook/timesformer/resolve/main/config.json',
}





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     str			= 'timesformer'





    def __init__(	self				:   int       ,   __snake_case				:   Any=224       ,   __snake_case				:   str=16       ,   __snake_case				:   Any=3       ,   __snake_case				:   List[Any]=8       ,   __snake_case				:   Dict=768       ,   __snake_case				:   Dict=12       ,   __snake_case				:   Tuple=12       ,   __snake_case				:   Dict=3_072       ,   __snake_case				:   str="gelu"       ,   __snake_case				:   Union[str, Any]=0.0       ,   __snake_case				:   List[Any]=0.0       ,   __snake_case				:   Tuple=0.02       ,   __snake_case				:   Optional[Any]=1E-6       ,   __snake_case				:   List[Any]=True       ,   __snake_case				:   List[str]="divided_space_time"       ,   __snake_case				:   Optional[int]=0       ,   **__snake_case				:   Dict       ,   ):





       '''simple docstring'''
       super().__init__(**__snake_case	)

       UpperCAmelCase_							:      Optional[int]						=   image_size
       UpperCAmelCase_							:      Optional[Any]						=   patch_size
       UpperCAmelCase_							:      Any						=   num_channels
       UpperCAmelCase_							:      int						=   num_frames

       UpperCAmelCase_							:      List[Any]						=   hidden_size
       UpperCAmelCase_							:      Any						=   num_hidden_layers
       UpperCAmelCase_							:      Dict						=   num_attention_heads
       UpperCAmelCase_							:      List[Any]						=   intermediate_size
       UpperCAmelCase_							:      str						=   hidden_act
       UpperCAmelCase_							:      List[str]						=   hidden_dropout_prob
       UpperCAmelCase_							:      List[str]						=   attention_probs_dropout_prob
       UpperCAmelCase_							:      Optional[int]						=   initializer_range
       UpperCAmelCase_							:      List[str]						=   layer_norm_eps
       UpperCAmelCase_							:      str						=   qkv_bias

       UpperCAmelCase_							:      Dict						=   attention_type
       UpperCAmelCase_							:      str						=   drop_path_rate