





"""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_video_inputs


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import VivitImageProcessor







class       a							(   unittest.TestCase  ):



 def __init__(     self				,       _snake_case				,       _snake_case=7				,       _snake_case=3				,       _snake_case=10				,       _snake_case=18				,       _snake_case=30				,       _snake_case=4_00				,       _snake_case=True				,       _snake_case=None				,       _snake_case=True				,       _snake_case=[0.5, 0.5, 0.5]				,       _snake_case=[0.5, 0.5, 0.5]				,       _snake_case=None				,       ):







  """simple docstring"""






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

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



 def    UpperCamelCase__  (     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       a							(   a_   , unittest.TestCase  ):
 snake_case__             =       VivitImageProcessor if is_vision_available() else None



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= VivitImageProcessingTester(self     )



 @property
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return self.image_processor_tester.prepare_image_processor_dict()



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






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



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= 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}     )

  lowerCAmelCase    				= 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     ):







  """simple docstring"""






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

  # Test not batched input
  lowerCAmelCase    				= 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
  lowerCAmelCase    				= image_processing(_snake_case				,       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    UpperCamelCase__  (     self     ):







  """simple docstring"""






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

  # Test not batched input
  lowerCAmelCase    				= 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
  lowerCAmelCase    				= image_processing(_snake_case				,       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    UpperCamelCase__  (     self     ):







  """simple docstring"""






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

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









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


UpperCAmelCase   :    str     =		logging.get_logger(__name__)

UpperCAmelCase   :    List[Any]     =		{
    "facebook/vit-mae-base": "https://huggingface.co/facebook/vit-mae-base/resolve/main/config.json",
    # See all ViT MAE models at https://huggingface.co/models?filter=vit-mae
}







class        __lowercase       (							a_  ):



		"""simple docstring"""

		UpperCamelCase     :					Optional[Any]			       =		"vit_mae"







		def __init__( self		,      A=7_68		,      A=12		,      A=12		,      A=30_72		,      A="gelu"		,      A=0.0		,      A=0.0		,      A=0.02		,      A=1e-1_2		,      A=2_24		,      A=16		,      A=3		,      A=True		,      A=16		,      A=5_12		,      A=8		,      A=20_48		,      A=0.75		,      A=False		,      **A		,      )  -> Dict:







					'''simple docstring'''







					super().__init__(**A	)

					lowerCamelCase    		=  hidden_size
					lowerCamelCase    		=  num_hidden_layers
					lowerCamelCase    		=  num_attention_heads
					lowerCamelCase    		=  intermediate_size
					lowerCamelCase    		=  hidden_act
					lowerCamelCase    		=  hidden_dropout_prob
					lowerCamelCase    		=  attention_probs_dropout_prob
					lowerCamelCase    		=  initializer_range
					lowerCamelCase    		=  layer_norm_eps
					lowerCamelCase    		=  image_size
					lowerCamelCase    		=  patch_size
					lowerCamelCase    		=  num_channels
					lowerCamelCase    		=  qkv_bias
					lowerCamelCase    		=  decoder_num_attention_heads
					lowerCamelCase    		=  decoder_hidden_size
					lowerCamelCase    		=  decoder_num_hidden_layers
					lowerCamelCase    		=  decoder_intermediate_size
					lowerCamelCase    		=  mask_ratio
					lowerCamelCase    		=  norm_pix_loss

