






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





		'''simple docstring'''



		def __init__(    self			,     UpperCamelCase__			,     UpperCamelCase__=7			,     UpperCamelCase__=3			,     UpperCamelCase__=18			,     UpperCamelCase__=30			,     UpperCamelCase__=400			,     UpperCamelCase__=True			,     UpperCamelCase__=1 / 255			,     UpperCamelCase__=True			,     UpperCamelCase__=8			,     ):
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= parent
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= batch_size
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= num_channels
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= image_size
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= min_resolution
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= max_resolution
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= do_rescale
						SCREAMING_SNAKE_CASE_ :						str    				= rescale_factor
						SCREAMING_SNAKE_CASE_ :						Dict    				= do_pad
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= pad_size


		def 	__snake_case      (    self							):
						return {
						    "do_rescale": self.do_rescale,
						    "rescale_factor": self.rescale_factor,
						    "do_pad": self.do_pad,
						    "pad_size": self.pad_size,
						}






		def 	__snake_case      (    self			,     UpperCamelCase__=False			,     UpperCamelCase__=False			,     UpperCamelCase__=False							):
						assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

						if torchify:
										SCREAMING_SNAKE_CASE_ :						int    				= [torch.from_numpy(UpperCamelCase__							) for x in image_inputs]

						return image_inputs






@require_torch
@require_vision
class 				__a				(	__A			,						unittest.TestCase    ):





		'''simple docstring'''



		UpperCAmelCase__   :					Tuple					     =    SwinaSRImageProcessor if is_vision_available() else None


		def 	__snake_case      (    self							):
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= SwinaSRImageProcessingTester(self							)


		@property
		def 	__snake_case      (    self							):
						return self.image_processor_tester.prepare_image_processor_dict()


		def 	__snake_case      (    self							):
						SCREAMING_SNAKE_CASE_ :						str    				= 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 	__snake_case      (    self							):
						pass


		def 	__snake_case      (    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						str    				= get_image_size(UpperCamelCase__							)
						SCREAMING_SNAKE_CASE_ :						int    				= self.image_processor_tester.pad_size

						SCREAMING_SNAKE_CASE_ :						int    				= (old_height // size + 1) * size - old_height
						SCREAMING_SNAKE_CASE_ :						Any    				= (old_width // size + 1) * size - old_width
						return old_height + pad_height, old_width + pad_width


		def 	__snake_case      (    self							):
						# Initialize image_processor
						SCREAMING_SNAKE_CASE_ :						int    				= self.image_processing_class(**self.image_processor_dict							)
						# create random PIL images
						SCREAMING_SNAKE_CASE_ :						int    				= self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__							)
						for image in image_inputs:
										self.assertIsInstance(UpperCamelCase__			,     Image.Image							)

						# Test not batched input
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= image_processor(image_inputs[0]			,     return_tensors='pt'							).pixel_values
						SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Union[str, 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 	__snake_case      (    self							):
						# Initialize image_processor
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= self.image_processing_class(**self.image_processor_dict							)
						# create random numpy tensors
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= 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
						SCREAMING_SNAKE_CASE_ :						Any    				= image_processor(image_inputs[0]			,     return_tensors='pt'							).pixel_values
						SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Dict    				= self.calculate_expected_size(image_inputs[0]							)
						self.assertEqual(
						    encoded_images.shape			,     (
						        1,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )			,     )






		def 	__snake_case      (    self							):
						# Initialize image_processor
						SCREAMING_SNAKE_CASE_ :						str    				= self.image_processing_class(**self.image_processor_dict							)
						# create random PyTorch tensors
						SCREAMING_SNAKE_CASE_ :						str    				= 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
						SCREAMING_SNAKE_CASE_ :						str    				= image_processor(image_inputs[0]			,     return_tensors='pt'							).pixel_values
						SCREAMING_SNAKE_CASE_				,							SCREAMING_SNAKE_CASE_ :						Dict    				= self.calculate_expected_size(image_inputs[0]							)
						self.assertEqual(
						    encoded_images.shape			,     (
						        1,
						        self.image_processor_tester.num_channels,
						        expected_height,
						        expected_width,
						    )			,     )







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


A										=      logging.get_logger(__name__)

A										=      {
    'ZinengTang/tvlt-base': 'https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json',
}


class 				__a				(	__A    ):





		'''simple docstring'''



		UpperCAmelCase__   :					str					     =    """tvlt"""


		def __init__(    self			,     UpperCamelCase__=224			,     UpperCamelCase__=2048			,     UpperCamelCase__=128			,     UpperCamelCase__=[16, 16]			,     UpperCamelCase__=[16, 16]			,     UpperCamelCase__=3			,     UpperCamelCase__=1			,     UpperCamelCase__=8			,     UpperCamelCase__=768			,     UpperCamelCase__=12			,     UpperCamelCase__=12			,     UpperCamelCase__=3072			,     UpperCamelCase__="gelu"			,     UpperCamelCase__=0.0			,     UpperCamelCase__=0.0			,     UpperCamelCase__=0.02			,     UpperCamelCase__=1E-6			,     UpperCamelCase__=True			,     UpperCamelCase__=False			,     UpperCamelCase__=16			,     UpperCamelCase__=512			,     UpperCamelCase__=8			,     UpperCamelCase__=2048			,     UpperCamelCase__=0.75			,     UpperCamelCase__=0.15			,     UpperCamelCase__="frame-level"			,     UpperCamelCase__=True			,     UpperCamelCase__=True			,     UpperCamelCase__="classification"			,     **UpperCamelCase__			,     ):
						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}'''							)

						SCREAMING_SNAKE_CASE_ :						Tuple    				= image_size
						SCREAMING_SNAKE_CASE_ :						int    				= spectrogram_length
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= frequency_length
						SCREAMING_SNAKE_CASE_ :						Any    				= image_patch_size
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= audio_patch_size
						SCREAMING_SNAKE_CASE_ :						int    				= num_image_channels
						SCREAMING_SNAKE_CASE_ :						Any    				= num_audio_channels
						SCREAMING_SNAKE_CASE_ :						Any    				= num_frames

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

						SCREAMING_SNAKE_CASE_ :						str    				= decoder_num_attention_heads
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= decoder_hidden_size
						SCREAMING_SNAKE_CASE_ :						Any    				= decoder_num_hidden_layers
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= decoder_intermediate_size
						SCREAMING_SNAKE_CASE_ :						List[str]    				= pixel_mask_ratio
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= audio_mask_ratio
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= audio_mask_type

						SCREAMING_SNAKE_CASE_ :						Any    				= task_matching
						SCREAMING_SNAKE_CASE_ :						Any    				= task_mae
						SCREAMING_SNAKE_CASE_ :						int    				= loss_type