


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


if is_torch_available():
       import torch

if is_vision_available():
       from PIL import Image

       from transformers import SwinaSRImageProcessor
       from transformers.image_transforms import get_image_size

class  lowercase_  ( unittest.TestCase						):







      def __init__(      self :							Union[str, Any]		,  _lowercase :							Union[str, Any]		,  _lowercase :							str=7		,  _lowercase :							str=3		,  _lowercase :							Tuple=1_8		,  _lowercase :							Union[str, Any]=3_0		,  _lowercase :							List[Any]=4_0_0		,  _lowercase :							Any=True		,  _lowercase :							Dict=1 / 2_5_5		,  _lowercase :							Any=True		,  _lowercase :							Dict=8		,  ):
        lowerCAmelCase__    :    Tuple								=					parent
        lowerCAmelCase__    :    Any								=					batch_size
        lowerCAmelCase__    :    Optional[int]								=					num_channels
        lowerCAmelCase__    :    Tuple								=					image_size
        lowerCAmelCase__    :    str								=					min_resolution
        lowerCAmelCase__    :    List[str]								=					max_resolution
        lowerCAmelCase__    :    Union[str, Any]								=					do_rescale
        lowerCAmelCase__    :    Tuple								=					rescale_factor
        lowerCAmelCase__    :    List[str]								=					do_pad
        lowerCAmelCase__    :    List[str]								=					pad_size







      def 				_lowerCAmelCase       (      self :							List[str]    ):
        return {
            "do_rescale": self.do_rescale,
            "rescale_factor": self.rescale_factor,
            "do_pad": self.do_pad,
            "pad_size": self.pad_size,
        }







      def 				_lowerCAmelCase       (      self :							List[str]		,  _lowercase :							Optional[Any]=False		,  _lowercase :							Dict=False		,  _lowercase :							Optional[Any]=False    ):
        assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

        if equal_resolution:
          lowerCAmelCase__    :    Dict								=					[]
          for i in range(self.batch_size    ):
            image_inputs.append(
                np.random.randint(
                    2_5_5		,  size=(self.num_channels, self.max_resolution, self.max_resolution)		,  dtype=np.uinta    )    )
        else:
          lowerCAmelCase__    :    List[Any]								=					[]
          for i in range(self.batch_size    ):
            lowerCAmelCase__    :    List[str]								=					np.random.choice(np.arange(self.min_resolution		,  self.max_resolution    )		,  2    )
            image_inputs.append(np.random.randint(2_5_5		,  size=(self.num_channels, width, height)		,  dtype=np.uinta    )    )

        if not numpify and not torchify:
          # PIL expects the channel dimension as last dimension
          lowerCAmelCase__    :    Tuple								=					[Image.fromarray(np.moveaxis(_lowercase		,  0		,  -1    )    ) for x in image_inputs]

        if torchify:
          lowerCAmelCase__    :    Tuple								=					[torch.from_numpy(_lowercase    ) for x in image_inputs]

        return image_inputs

@require_torch
@require_vision
class  lowercase_  ( a_							,							unittest.TestCase						):
      __magic_name__     :							Any          =				SwinaSRImageProcessor if is_vision_available() else None







      def 				_lowerCAmelCase       (      self :							List[Any]    ):
        lowerCAmelCase__    :    Union[str, Any]								=					SwinaSRImageProcessingTester(self    )







      @property
      def 				_lowerCAmelCase       (      self :							Optional[int]    ):
        return self.image_processor_tester.prepare_image_processor_dict()







      def 				_lowerCAmelCase       (      self :							List[str]    ):
        lowerCAmelCase__    :    List[Any]								=					self.image_processing_class(**self.image_processor_dict    )
        self.assertTrue(hasattr(_lowercase		,  "do_rescale"    )    )
        self.assertTrue(hasattr(_lowercase		,  "rescale_factor"    )    )
        self.assertTrue(hasattr(_lowercase		,  "do_pad"    )    )
        self.assertTrue(hasattr(_lowercase		,  "pad_size"    )    )







      def 				_lowerCAmelCase       (      self :							int    ):
        pass







      def 				_lowerCAmelCase       (      self :							Dict		,  _lowercase :							List[str]    ):
        lowerCAmelCase__    :    Any								=					get_image_size(_lowercase    )
        lowerCAmelCase__    :    Any								=					self.image_processor_tester.pad_size

        lowerCAmelCase__    :    Optional[int]								=					(old_height // size + 1) * size - old_height
        lowerCAmelCase__    :    Optional[int]								=					(old_width // size + 1) * size - old_width
        return old_height + pad_height, old_width + pad_width







      def 				_lowerCAmelCase       (      self :							Union[str, Any]    ):
        # Initialize image_processor
        lowerCAmelCase__    :    Any								=					self.image_processing_class(**self.image_processor_dict    )
        # create random PIL images
        lowerCAmelCase__    :    Union[str, Any]								=					self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase    )
        for image in image_inputs:
          self.assertIsInstance(_lowercase		,  Image.Image    )

        # Test not batched input
        lowerCAmelCase__    :    List[str]								=					image_processor(image_inputs[0]		,  return_tensors="pt"    ).pixel_values
        lowerCAmelCase__    :    Any								=					self.calculate_expected_size(np.array(image_inputs[0]    )    )
        self.assertEqual(
            encoded_images.shape		,  (
                1,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )		,  )







      def 				_lowerCAmelCase       (      self :							Union[str, Any]    ):
        # Initialize image_processor
        lowerCAmelCase__    :    Dict								=					self.image_processing_class(**self.image_processor_dict    )
        # create random numpy tensors
        lowerCAmelCase__    :    str								=					self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase		,  numpify=_lowercase    )
        for image in image_inputs:
          self.assertIsInstance(_lowercase		,  np.ndarray    )

        # Test not batched input
        lowerCAmelCase__    :    Optional[Any]								=					image_processor(image_inputs[0]		,  return_tensors="pt"    ).pixel_values
        lowerCAmelCase__    :    int								=					self.calculate_expected_size(image_inputs[0]    )
        self.assertEqual(
            encoded_images.shape		,  (
                1,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )		,  )







      def 				_lowerCAmelCase       (      self :							List[Any]    ):
        # Initialize image_processor
        lowerCAmelCase__    :    Dict								=					self.image_processing_class(**self.image_processor_dict    )
        # create random PyTorch tensors
        lowerCAmelCase__    :    Any								=					self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase		,  torchify=_lowercase    )
        for image in image_inputs:
          self.assertIsInstance(_lowercase		,  torch.Tensor    )

        # Test not batched input
        lowerCAmelCase__    :    str								=					image_processor(image_inputs[0]		,  return_tensors="pt"    ).pixel_values
        lowerCAmelCase__    :    Optional[Any]								=					self.calculate_expected_size(image_inputs[0]    )
        self.assertEqual(
            encoded_images.shape		,  (
                1,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )		,  )




"""simple docstring"""





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  lowercase_  ( a_						):
      __magic_name__     :							Union[str, Any]          =				"""videomae"""







      def __init__(      self :							Dict		,  _lowercase :							int=2_2_4		,  _lowercase :							Optional[Any]=1_6		,  _lowercase :							List[Any]=3		,  _lowercase :							int=1_6		,  _lowercase :							Optional[Any]=2		,  _lowercase :							Union[str, Any]=7_6_8		,  _lowercase :							int=1_2		,  _lowercase :							Dict=1_2		,  _lowercase :							Optional[Any]=3_0_7_2		,  _lowercase :							List[str]="gelu"		,  _lowercase :							int=0.0		,  _lowercase :							int=0.0		,  _lowercase :							Optional[int]=0.02		,  _lowercase :							List[str]=1e-1_2		,  _lowercase :							Union[str, Any]=True		,  _lowercase :							Union[str, Any]=True		,  _lowercase :							Any=6		,  _lowercase :							Any=3_8_4		,  _lowercase :							int=4		,  _lowercase :							Optional[int]=1_5_3_6		,  _lowercase :							Tuple=True		,  **_lowercase :							List[str]		,  ):
        super().__init__(**_lowercase    )

        lowerCAmelCase__    :    List[Any]								=					image_size
        lowerCAmelCase__    :    Tuple								=					patch_size
        lowerCAmelCase__    :    Union[str, Any]								=					num_channels
        lowerCAmelCase__    :    Optional[Any]								=					num_frames
        lowerCAmelCase__    :    Union[str, Any]								=					tubelet_size

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

        lowerCAmelCase__    :    List[Any]								=					decoder_num_attention_heads
        lowerCAmelCase__    :    List[str]								=					decoder_hidden_size
        lowerCAmelCase__    :    int								=					decoder_num_hidden_layers
        lowerCAmelCase__    :    Optional[int]								=					decoder_intermediate_size
        lowerCAmelCase__    :    Optional[Any]								=					norm_pix_loss
