





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 ViltImageProcessor



class 							_UpperCamelCase    (		unittest.TestCase   ):

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




              """simple docstring"""


              UpperCamelCase_      				=     size if size is not None else {"shortest_edge": 30}
              UpperCamelCase_      				=     parent
              UpperCamelCase_      				=     batch_size
              UpperCamelCase_      				=     num_channels
              UpperCamelCase_      				=     image_size
              UpperCamelCase_      				=     min_resolution
              UpperCamelCase_      				=     max_resolution
              UpperCamelCase_      				=     do_resize
              UpperCamelCase_      				=     size
              UpperCamelCase_      				=     size_divisor
              UpperCamelCase_      				=     do_normalize
              UpperCamelCase_      				=     image_mean
              UpperCamelCase_      				=     image_std

       def lowercase       (						self:       str						)				->       Any:




              """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,
                  "size_divisor": self.size_divisor,
              }



       def lowercase       (						self:       Union[str, Any]    ,      _SCREAMING_SNAKE_CASE:       Optional[int]    ,      _SCREAMING_SNAKE_CASE:       int=False						)				->       Union[str, Any]:




              """simple docstring"""


              if not batched:
                     UpperCamelCase_      				=     self.size["shortest_edge"]
                     UpperCamelCase_      				=     image_inputs[0]
                     if isinstance(_SCREAMING_SNAKE_CASE    ,      Image.Image						):
                            UpperCamelCase_				,       UpperCamelCase_      				=     image.size
                     else:
                            UpperCamelCase_				,       UpperCamelCase_      				=     image.shape[1], image.shape[2]
                     UpperCamelCase_      				=     size / min(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						)
                     if h < w:
                            UpperCamelCase_				,       UpperCamelCase_      				=     size, scale * w
                     else:
                            UpperCamelCase_				,       UpperCamelCase_      				=     scale * h, size

                     UpperCamelCase_      				=     int((1333 / 800) * size						)
                     if max(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						) > max_size:
                            UpperCamelCase_      				=     max_size / max(_SCREAMING_SNAKE_CASE    ,      _SCREAMING_SNAKE_CASE						)
                            UpperCamelCase_      				=     newh * scale
                            UpperCamelCase_      				=     neww * scale

                     UpperCamelCase_				,       UpperCamelCase_      				=     int(newh + 0.5						), int(neww + 0.5						)
                     UpperCamelCase_				,       UpperCamelCase_      				=     (
                         newh // self.size_divisor * self.size_divisor,
                         neww // self.size_divisor * self.size_divisor,
                     )

              else:
                     UpperCamelCase_      				=     []
                     for image in image_inputs:
                            UpperCamelCase_				,       UpperCamelCase_      				=     self.get_expected_values([image]						)
                            expected_values.append((expected_height, expected_width)						)
                     UpperCamelCase_      				=     max(_SCREAMING_SNAKE_CASE    ,      key=lambda _SCREAMING_SNAKE_CASE						: item[0]						)[0]
                     UpperCamelCase_      				=     max(_SCREAMING_SNAKE_CASE    ,      key=lambda _SCREAMING_SNAKE_CASE						: item[1]						)[1]

              return expected_height, expected_width



@require_torch
@require_vision
class 							_UpperCamelCase    (		lowerCAmelCase_     ,  unittest.TestCase   ):
       _UpperCamelCase :    List[str]   			=      ViltImageProcessor if is_vision_available() else None

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




              """simple docstring"""


              UpperCamelCase_      				=     ViltImageProcessingTester(self						)

       @property
       def lowercase       (						self:       Tuple						)				->       List[Any]:




              """simple docstring"""


              return self.image_processor_tester.prepare_image_processor_dict()

       def lowercase       (						self:       Dict						)				->       Union[str, Any]:




              """simple docstring"""


              UpperCamelCase_      				=     self.image_processing_class(**self.image_processor_dict						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "image_mean"						)						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "image_std"						)						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "do_normalize"						)						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "do_resize"						)						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "size"						)						)
              self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE    ,      "size_divisor"						)						)

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




              """simple docstring"""


              UpperCamelCase_      				=     self.image_processing_class.from_dict(self.image_processor_dict						)
              self.assertEqual(image_processor.size    ,      {"shortest_edge": 30}						)

              UpperCamelCase_      				=     self.image_processing_class.from_dict(self.image_processor_dict    ,      size=42						)
              self.assertEqual(image_processor.size    ,      {"shortest_edge": 42}						)

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




              """simple docstring"""


              pass

       def lowercase       (						self:       Optional[Any]						)				->       Tuple:




              """simple docstring"""


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

              # Test not batched input
              UpperCamelCase_      				=     image_processing(image_inputs[0]    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,      )

              # Test batched
              UpperCamelCase_      				=     image_processing(_SCREAMING_SNAKE_CASE    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE    ,      batched=_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  )    ,      )

       def lowercase       (						self:       int						)				->       Any:




              """simple docstring"""


              UpperCamelCase_      				=     self.image_processing_class(**self.image_processor_dict						)
              # create random numpy tensors
              UpperCamelCase_      				=     prepare_image_inputs(self.image_processor_tester    ,      equal_resolution=_SCREAMING_SNAKE_CASE    ,      numpify=_SCREAMING_SNAKE_CASE						)
              for image in image_inputs:
                     self.assertIsInstance(_SCREAMING_SNAKE_CASE    ,      np.ndarray						)

              # Test not batched input
              UpperCamelCase_      				=     image_processing(image_inputs[0]    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,      )

              # Test batched
              UpperCamelCase_      				=     image_processing(_SCREAMING_SNAKE_CASE    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE    ,      batched=_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  )    ,      )



       def lowercase       (						self:       Dict						)				->       List[Any]:




              """simple docstring"""


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

              # Test not batched input
              UpperCamelCase_      				=     image_processing(image_inputs[0]    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)    ,      )

              # Test batched
              UpperCamelCase_      				=     image_processing(_SCREAMING_SNAKE_CASE    ,      return_tensors="pt"						).pixel_values

              UpperCamelCase_				,       UpperCamelCase_      				=     self.image_processor_tester.get_expected_values(_SCREAMING_SNAKE_CASE    ,      batched=_SCREAMING_SNAKE_CASE						)
              self.assertEqual(
                  encoded_images.shape    ,      (
                      self.image_processor_tester.batch_size,
                      self.image_processor_tester.num_channels,
                      expected_height,
                      expected_width,
                  )    ,      )








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


_UpperCAmelCase				       = logging.get_logger(__name__)

_UpperCAmelCase				       = {
    'MCG-NJU/videomae-base': 'https://huggingface.co/MCG-NJU/videomae-base/resolve/main/config.json',
}



class 							_UpperCamelCase    (		lowerCAmelCase_   ):
       _UpperCamelCase :    List[Any]   			=      '''videomae'''

       def __init__(						self:       Optional[Any]    ,      _SCREAMING_SNAKE_CASE:       List[str]=224    ,      _SCREAMING_SNAKE_CASE:       Dict=16    ,      _SCREAMING_SNAKE_CASE:       List[Any]=3    ,      _SCREAMING_SNAKE_CASE:       Tuple=16    ,      _SCREAMING_SNAKE_CASE:       Tuple=2    ,      _SCREAMING_SNAKE_CASE:       Optional[Any]=768    ,      _SCREAMING_SNAKE_CASE:       str=12    ,      _SCREAMING_SNAKE_CASE:       List[Any]=12    ,      _SCREAMING_SNAKE_CASE:       Dict=3072    ,      _SCREAMING_SNAKE_CASE:       Tuple="gelu"    ,      _SCREAMING_SNAKE_CASE:       List[Any]=0.0    ,      _SCREAMING_SNAKE_CASE:       List[Any]=0.0    ,      _SCREAMING_SNAKE_CASE:       Tuple=0.02    ,      _SCREAMING_SNAKE_CASE:       Optional[int]=1e-12    ,      _SCREAMING_SNAKE_CASE:       Dict=True    ,      _SCREAMING_SNAKE_CASE:       Dict=True    ,      _SCREAMING_SNAKE_CASE:       List[str]=6    ,      _SCREAMING_SNAKE_CASE:       Dict=384    ,      _SCREAMING_SNAKE_CASE:       Any=4    ,      _SCREAMING_SNAKE_CASE:       Dict=1536    ,      _SCREAMING_SNAKE_CASE:       Optional[int]=True    ,      **_SCREAMING_SNAKE_CASE:       str    ,      )				->       Dict:




              """simple docstring"""


              super().__init__(**_SCREAMING_SNAKE_CASE						)

              UpperCamelCase_      				=     image_size
              UpperCamelCase_      				=     patch_size
              UpperCamelCase_      				=     num_channels
              UpperCamelCase_      				=     num_frames
              UpperCamelCase_      				=     tubelet_size

              UpperCamelCase_      				=     hidden_size
              UpperCamelCase_      				=     num_hidden_layers
              UpperCamelCase_      				=     num_attention_heads
              UpperCamelCase_      				=     intermediate_size
              UpperCamelCase_      				=     hidden_act
              UpperCamelCase_      				=     hidden_dropout_prob
              UpperCamelCase_      				=     attention_probs_dropout_prob
              UpperCamelCase_      				=     initializer_range
              UpperCamelCase_      				=     layer_norm_eps
              UpperCamelCase_      				=     qkv_bias
              UpperCamelCase_      				=     use_mean_pooling

              UpperCamelCase_      				=     decoder_num_attention_heads
              UpperCamelCase_      				=     decoder_hidden_size
              UpperCamelCase_      				=     decoder_num_hidden_layers
              UpperCamelCase_      				=     decoder_intermediate_size
              UpperCamelCase_      				=     norm_pix_loss

