



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 				A      (	_UpperCAmelCase							:  Any				,  _UpperCAmelCase							:  Union[str, Any]=10				,  _UpperCAmelCase							:  Optional[int]=10				,  _UpperCAmelCase							:  Optional[Any]=False				,  _UpperCAmelCase							:  int=False       )							->					Tuple:







			'''simple docstring'''
			_UpperCAmelCase									=  []
			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
						_UpperCAmelCase									=  [Image.fromarray(np.moveaxis(_UpperCAmelCase				,  0				,  -1       )       ) for frame in video]

			if torchify:
						_UpperCAmelCase									=  [torch.from_numpy(_UpperCAmelCase       ) for frame in video]

			return video





def 				A      (	_UpperCAmelCase							:  Union[str, Any]				,  _UpperCAmelCase							:  str=False				,  _UpperCAmelCase							:  int=False				,  _UpperCAmelCase							:  Dict=False       )							->					Union[str, Any]:







			'''simple docstring'''
			assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

			_UpperCAmelCase									=  []
			for i in range(image_processor_tester.batch_size       ):
						if equal_resolution:
									_UpperCAmelCase									=  _UpperCAmelCase									=  image_processor_tester.max_resolution
						else:
									_UpperCAmelCase			,	_UpperCAmelCase									=  np.random.choice(
									    np.arange(image_processor_tester.min_resolution				,  image_processor_tester.max_resolution       )				,  2       )
									_UpperCAmelCase									=  prepare_video(
									    image_processor_tester=_UpperCAmelCase				,  width=_UpperCAmelCase				,  height=_UpperCAmelCase				,  numpify=_UpperCAmelCase				,  torchify=_UpperCAmelCase				,  )
						video_inputs.append(_UpperCAmelCase       )

			return video_inputs







class      __lowerCAmelCase       (     unittest.TestCase		):



			def __init__(		self  :    Optional[Any]					,						A  :    Union[str, Any]					,						A  :    List[str]=7					,						A  :    Optional[int]=3					,						A  :    int=4					,						A  :    Optional[Any]=18					,						A  :    Union[str, Any]=30					,						A  :    Optional[Any]=4_00					,						A  :    Any=True					,						A  :    Dict=None					,						A  :    List[str]=True					,						A  :    int=[0.5, 0.5, 0.5]					,						A  :    Union[str, Any]=[0.5, 0.5, 0.5]					,						A  :    str=True					,						A  :    int=None					,						)  ->       Dict:



						"""simple docstring"""






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

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



			def        _lowerCamelCase			(		self  :    int)  ->       Dict:



						"""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,
						    "do_center_crop": self.do_center_crop,
						    "crop_size": self.crop_size,
						}







@require_torch
@require_vision
class      __lowerCAmelCase       (     A							,		unittest.TestCase		):
			UpperCamelCase     =	TvltImageProcessor if is_vision_available() else None



			def        _lowerCamelCase			(		self  :    Tuple)  ->       Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase									=  TvltImageProcessorTester(self)



			@property
			def        _lowerCamelCase			(		self  :    Dict)  ->       List[str]:



						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()



			def        _lowerCamelCase			(		self  :    Optional[int])  ->       str:



						"""simple docstring"""






						_UpperCAmelCase									=  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        _lowerCamelCase			(		self  :    Optional[Any])  ->       List[Any]:



						"""simple docstring"""






						_UpperCAmelCase									=  self.image_processing_class(**self.image_processor_dict)
						# create random PIL videos
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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        _lowerCamelCase			(		self  :    Optional[int])  ->       Dict:



						"""simple docstring"""






						_UpperCAmelCase									=  self.image_processing_class(**self.image_processor_dict)
						# create random numpy tensors
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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        _lowerCamelCase			(		self  :    List[Any])  ->       str:



						"""simple docstring"""






						_UpperCAmelCase									=  self.image_processing_class(**self.image_processor_dict)
						# create random PyTorch tensors
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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
						_UpperCAmelCase									=  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'],
						    )					,						)





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


UpperCAmelCase__  =			logging.get_logger(__name__)

UpperCAmelCase__  =			{
    "dandelin/vilt-b32-mlm": "https://huggingface.co/dandelin/vilt-b32-mlm/blob/main/config.json"
}







class      __lowerCAmelCase       (     A		):
			UpperCamelCase     =	'''vilt'''



			def __init__(		self  :    List[Any]					,						A  :    Dict=3_05_22					,						A  :    Union[str, Any]=2					,						A  :    Tuple=2					,						A  :    List[Any]=40					,						A  :    Optional[int]=7_68					,						A  :    Any=12					,						A  :    Optional[int]=12					,						A  :    Optional[Any]=30_72					,						A  :    Optional[Any]="gelu"					,						A  :    str=0.0					,						A  :    Any=0.0					,						A  :    Union[str, Any]=0.0_2					,						A  :    Union[str, Any]=1E-12					,						A  :    Optional[Any]=3_84					,						A  :    Dict=32					,						A  :    int=3					,						A  :    int=True					,						A  :    Union[str, Any]=-1					,						A  :    int=False					,						A  :    int=-1					,						**A  :    Tuple					,						)  ->       Dict:



						"""simple docstring"""






						super().__init__(tie_word_embeddings=A					,						**A)

						_UpperCAmelCase									=  vocab_size
						_UpperCAmelCase									=  type_vocab_size
						_UpperCAmelCase									=  modality_type_vocab_size
						_UpperCAmelCase									=  max_position_embeddings

						_UpperCAmelCase									=  hidden_size
						_UpperCAmelCase									=  num_hidden_layers
						_UpperCAmelCase									=  num_attention_heads
						_UpperCAmelCase									=  intermediate_size
						_UpperCAmelCase									=  hidden_act
						_UpperCAmelCase									=  hidden_dropout_prob
						_UpperCAmelCase									=  attention_probs_dropout_prob
						_UpperCAmelCase									=  initializer_range
						_UpperCAmelCase									=  layer_norm_eps

						_UpperCAmelCase									=  image_size
						_UpperCAmelCase									=  patch_size
						_UpperCAmelCase									=  num_channels
						_UpperCAmelCase									=  qkv_bias
						_UpperCAmelCase									=  max_image_length
						_UpperCAmelCase									=  num_images
