





"""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  _UpperCAmelCase      (     unittest.TestCase			):


					def __init__( self      :Union[str, Any]					,	__UpperCamelCase      :int					,	__UpperCamelCase      :Optional[Any]=7					,	__UpperCamelCase      :int=3					,	__UpperCamelCase      :int=18					,	__UpperCamelCase      :int=30					,	__UpperCamelCase      :Any=4_00					,	__UpperCamelCase      :Any=True					,	__UpperCamelCase      :Optional[Any]=1 / 2_55					,	__UpperCamelCase      :List[str]=True					,	__UpperCamelCase      :Any=8					,	):
												A		=  parent
												A		=  batch_size
												A		=  num_channels
												A		=  image_size
												A		=  min_resolution
												A		=  max_resolution
												A		=  do_rescale
												A		=  rescale_factor
												A		=  do_pad
												A		=  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      :str					,	__UpperCamelCase      :Optional[Any]=False					,	__UpperCamelCase      :Tuple=False					,	__UpperCamelCase      :List[Any]=False		):
												assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

												if torchify:
																			A		=  [torch.from_numpy(UpperCamelCase_		) for x in image_inputs]

												return image_inputs







@require_torch
@require_vision
class  _UpperCAmelCase      (     lowercase_					,							unittest.TestCase			):
					UpperCamelCase								=							SwinaSRImageProcessor if is_vision_available() else None


					def      lowerCamelCase	( self      :str		):
												A		=  SwinaSRImageProcessingTester(self		)


					@property
					def      lowerCamelCase	( self      :Tuple		):
												return self.image_processor_tester.prepare_image_processor_dict()


					def      lowerCamelCase	( self      :int		):
												A		=  self.image_processing_class(**self.image_processor_dict		)
												self.assertTrue(hasattr(UpperCamelCase_					,	"do_rescale"		)		)
												self.assertTrue(hasattr(UpperCamelCase_					,	"rescale_factor"		)		)
												self.assertTrue(hasattr(UpperCamelCase_					,	"do_pad"		)		)
												self.assertTrue(hasattr(UpperCamelCase_					,	"pad_size"		)		)


					def      lowerCamelCase	( self      :List[str]		):
												pass


					def      lowerCamelCase	( self      :Tuple					,	__UpperCamelCase      :List[Any]		):
												A,     A		=  get_image_size(UpperCamelCase_		)
												A		=  self.image_processor_tester.pad_size

												A		=  (old_height // size + 1) * size - old_height
												A		=  (old_width // size + 1) * size - old_width
												return old_height + pad_height, old_width + pad_width


					def      lowerCamelCase	( self      :Optional[int]		):
												A		=  self.image_processing_class(**self.image_processor_dict		)
												# create random PIL images
												A		=  self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase_		)
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase_					,	Image.Image		)

												# Test not batched input
												A		=  image_processor(image_inputs[0]					,	return_tensors="pt"		).pixel_values
												A,     A		=  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      :Any		):
												A		=  self.image_processing_class(**self.image_processor_dict		)
												# create random numpy tensors
												A		=  self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase_					,	numpify=UpperCamelCase_		)
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase_					,	np.ndarray		)

												# Test not batched input
												A		=  image_processor(image_inputs[0]					,	return_tensors="pt"		).pixel_values
												A,     A		=  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      :Any		):
												A		=  self.image_processing_class(**self.image_processor_dict		)
												# create random PyTorch tensors
												A		=  self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase_					,	torchify=UpperCamelCase_		)
												for image in image_inputs:
																			self.assertIsInstance(UpperCamelCase_					,	torch.Tensor		)

												# Test not batched input
												A		=  image_processor(image_inputs[0]					,	return_tensors="pt"		).pixel_values
												A,     A		=  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


_snake_case					:		Optional[int]							=			logging.get_logger(__name__)

_snake_case					:		List[Any]							=			{
    'ZinengTang/tvlt-base': 'https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json',
}






class  _UpperCAmelCase       (     lowercase_			):
					UpperCamelCase								=							'''tvlt'''


					def __init__( self      :Dict					,	__UpperCamelCase      :Tuple=2_24					,	__UpperCamelCase      :Dict=20_48					,	__UpperCamelCase      :Optional[Any]=1_28					,	__UpperCamelCase      :Optional[int]=[16, 16]					,	__UpperCamelCase      :Any=[16, 16]					,	__UpperCamelCase      :List[str]=3					,	__UpperCamelCase      :str=1					,	__UpperCamelCase      :List[str]=8					,	__UpperCamelCase      :str=7_68					,	__UpperCamelCase      :List[str]=12					,	__UpperCamelCase      :Tuple=12					,	__UpperCamelCase      :Union[str, Any]=30_72					,	__UpperCamelCase      :List[Any]="gelu"					,	__UpperCamelCase      :List[str]=0.0					,	__UpperCamelCase      :Union[str, Any]=0.0					,	__UpperCamelCase      :List[str]=0.02					,	__UpperCamelCase      :Dict=1e-6					,	__UpperCamelCase      :Any=True					,	__UpperCamelCase      :List[str]=False					,	__UpperCamelCase      :str=16					,	__UpperCamelCase      :List[str]=5_12					,	__UpperCamelCase      :int=8					,	__UpperCamelCase      :int=20_48					,	__UpperCamelCase      :int=0.75					,	__UpperCamelCase      :Tuple=0.15					,	__UpperCamelCase      :Optional[Any]="frame-level"					,	__UpperCamelCase      :int=True					,	__UpperCamelCase      :str=True					,	__UpperCamelCase      :Tuple="classification"					,	**__UpperCamelCase      :Any					,	):
												super().__init__(**__UpperCamelCase		)

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

												A		=  image_size
												A		=  spectrogram_length
												A		=  frequency_length
												A		=  image_patch_size
												A		=  audio_patch_size
												A		=  num_image_channels
												A		=  num_audio_channels
												A		=  num_frames

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

												A		=  decoder_num_attention_heads
												A		=  decoder_hidden_size
												A		=  decoder_num_hidden_layers
												A		=  decoder_intermediate_size
												A		=  pixel_mask_ratio
												A		=  audio_mask_ratio
												A		=  audio_mask_type

												A		=  task_matching
												A		=  task_mae
												A		=  loss_type


