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


def   __magic_name__     (				__snake_case    :	int					,			__snake_case    :	str=10					,			__snake_case    :	List[Any]=10					,			__snake_case    :	List[Any]=False					,			__snake_case    :	Optional[Any]=False  )			->    Optional[Any]:
       lowercase   :    str			=							[]
       for i in range(image_processor_tester.num_frames  ):
              video.append(np.random.randint(255					,			size=(image_processor_tester.num_channels, width, height)					,			dtype=np.uinta  )  )

       if not numpify and not torchify:
              # PIL expects the channel dimension as last dimension
              lowercase   :    Union[str, Any]			=							[Image.fromarray(np.moveaxis(__snake_case					,			0					,			-1  )  ) for frame in video]

       if torchify:
              lowercase   :    Optional[Any]			=							[torch.from_numpy(__snake_case  ) for frame in video]

       return video


def   __magic_name__     (				__snake_case    :	Dict					,			__snake_case    :	Optional[Any]=False					,			__snake_case    :	Optional[Any]=False					,			__snake_case    :	Optional[Any]=False  )			->    Optional[Any]:
       assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

       lowercase   :    Any			=							[]
       for i in range(image_processor_tester.batch_size  ):
              if equal_resolution:
                     lowercase   :    Optional[int]			=							image_processor_tester.max_resolution
              else:
                     lowercase		,   lowercase   :    Any			=							np.random.choice(
                         np.arange(image_processor_tester.min_resolution					,			image_processor_tester.max_resolution  )					,			2  )
                     lowercase   :    Union[str, Any]			=							prepare_video(
                         image_processor_tester=__snake_case					,			width=__snake_case					,			height=__snake_case					,			numpify=__snake_case					,			torchify=__snake_case					,			)
              video_inputs.append(__snake_case  )

       return video_inputs

class 		a__						(				unittest.TestCase						):
   def __init__(      self     ,   _a     ,   _a=7     ,   _a=3     ,   _a=4     ,   _a=18     ,   _a=30     ,   _a=400     ,   _a=True     ,   _a=None     ,   _a=True     ,   _a=[0.5, 0.5, 0.5]     ,   _a=[0.5, 0.5, 0.5]     ,   _a=True     ,   _a=None     ,   ):
          lowercase   :    List[str]			=							size if size is not None else {"shortest_edge": 18}
          lowercase   :    Union[str, Any]			=							crop_size if crop_size is not None else {"height": 18, "width": 18}

          lowercase   :    int			=							parent
          lowercase   :    Optional[int]			=							batch_size
          lowercase   :    List[str]			=							num_channels
          lowercase   :    Any			=							num_frames
          lowercase   :    Optional[int]			=							image_size
          lowercase   :    Optional[int]			=							min_resolution
          lowercase   :    Optional[int]			=							max_resolution
          lowercase   :    Tuple			=							do_resize
          lowercase   :    Union[str, Any]			=							size
          lowercase   :    Any			=							do_normalize
          lowercase   :    int			=							image_mean
          lowercase   :    Tuple			=							image_std
          lowercase   :    Dict			=							do_center_crop
          lowercase   :    Optional[int]			=							crop_size

   def       __magic_name__      (      self    ):
          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }


@require_torch
@require_vision
class 		a__						(				a_,      unittest.TestCase						):
   __lowerCAmelCase						=    TvltImageProcessor if is_vision_available() else None
   def       __magic_name__      (      self    ):
          lowercase   :    Any			=							TvltImageProcessorTester(self    )
   @property
   def       __magic_name__      (      self    ):
          return self.image_processor_tester.prepare_image_processor_dict()
   def       __magic_name__      (      self    ):
          lowercase   :    Any			=							self.image_processing_class(**self.image_processor_dict    )
          self.assertTrue(hasattr(_a     ,   "image_mean"    )    )
          self.assertTrue(hasattr(_a     ,   "image_std"    )    )
          self.assertTrue(hasattr(_a     ,   "do_normalize"    )    )
          self.assertTrue(hasattr(_a     ,   "do_resize"    )    )
          self.assertTrue(hasattr(_a     ,   "do_center_crop"    )    )
          self.assertTrue(hasattr(_a     ,   "size"    )    )
   def       __magic_name__      (      self    ):
          # Initialize image_processor
          lowercase   :    List[Any]			=							self.image_processing_class(**self.image_processor_dict    )
          # create random PIL videos
          lowercase   :    Optional[Any]			=							prepare_video_inputs(self.image_processor_tester     ,   equal_resolution=_a    )
          for video in video_inputs:
                 self.assertIsInstance(_a     ,   _a    )
                 self.assertIsInstance(video[0]     ,   Image.Image    )

          # Test not batched input
          lowercase   :    str			=							image_processor(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
          lowercase   :    Tuple			=							image_processor(_a     ,   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       __magic_name__      (      self    ):
          # Initialize image_processor
          lowercase   :    Union[str, Any]			=							self.image_processing_class(**self.image_processor_dict    )
          # create random numpy tensors
          lowercase   :    Union[str, Any]			=							prepare_video_inputs(self.image_processor_tester     ,   equal_resolution=_a     ,   numpify=_a    )
          for video in video_inputs:
                 self.assertIsInstance(_a     ,   _a    )
                 self.assertIsInstance(video[0]     ,   np.ndarray    )

          # Test not batched input
          lowercase   :    str			=							image_processor(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
          lowercase   :    int			=							image_processor(_a     ,   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       __magic_name__      (      self    ):
          # Initialize image_processor
          lowercase   :    int			=							self.image_processing_class(**self.image_processor_dict    )
          # create random PyTorch tensors
          lowercase   :    List[str]			=							prepare_video_inputs(self.image_processor_tester     ,   equal_resolution=_a     ,   torchify=_a    )
          for video in video_inputs:
                 self.assertIsInstance(_a     ,   _a    )
                 self.assertIsInstance(video[0]     ,   torch.Tensor    )

          # Test not batched input
          lowercase   :    Dict			=							image_processor(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
          lowercase   :    Dict			=							image_processor(_a     ,   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"],
              )     ,   )




"""simple docstring"""




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


_A      :	str       		=	logging.get_logger(__name__)

_A      :	Optional[int]       		=	{
    """ZinengTang/tvlt-base""": """https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json""",
}

class 		a__						(				a_						):
   __lowerCAmelCase						=    """tvlt"""
   def __init__(      self     ,   _a=224     ,   _a=2_048     ,   _a=128     ,   _a=[16, 16]     ,   _a=[16, 16]     ,   _a=3     ,   _a=1     ,   _a=8     ,   _a=768     ,   _a=12     ,   _a=12     ,   _a=3_072     ,   _a="gelu"     ,   _a=0.0     ,   _a=0.0     ,   _a=0.0_2     ,   _a=1E-6     ,   _a=True     ,   _a=False     ,   _a=16     ,   _a=512     ,   _a=8     ,   _a=2_048     ,   _a=0.7_5     ,   _a=0.1_5     ,   _a="frame-level"     ,   _a=True     ,   _a=True     ,   _a="classification"     ,   **_a     ,   ):
          super().__init__(**_a    )

          if audio_mask_type not in ("frame-level", "patch_level"):
                 raise ValueError(
                     "audio_mask_type must be one of two acceptable strategies - {'frame_level', 'patch-level') "
                     f"""got {audio_mask_type}"""    )

          lowercase   :    Union[str, Any]			=							image_size
          lowercase   :    Dict			=							spectrogram_length
          lowercase   :    Union[str, Any]			=							frequency_length
          lowercase   :    Union[str, Any]			=							image_patch_size
          lowercase   :    Any			=							audio_patch_size
          lowercase   :    int			=							num_image_channels
          lowercase   :    Union[str, Any]			=							num_audio_channels
          lowercase   :    Any			=							num_frames

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

          lowercase   :    List[Any]			=							decoder_num_attention_heads
          lowercase   :    Union[str, Any]			=							decoder_hidden_size
          lowercase   :    Dict			=							decoder_num_hidden_layers
          lowercase   :    Union[str, Any]			=							decoder_intermediate_size
          lowercase   :    List[str]			=							pixel_mask_ratio
          lowercase   :    str			=							audio_mask_ratio
          lowercase   :    Any			=							audio_mask_type

          lowercase   :    Union[str, Any]			=							task_matching
          lowercase   :    Optional[Any]			=							task_mae
          lowercase   :    List[str]			=							loss_type


