



"""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 	lowerCAmelCase__      (  lowerCamelCase__					,   lowerCamelCase__=10					,   lowerCamelCase__=10					,   lowerCamelCase__=False					,   lowerCamelCase__=False      )			->				Tuple:
							A    =       []
							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
														A    =       [Image.fromarray(np.moveaxis(__lowerCamelCase					,   0					,   -1      )      ) for frame in video]

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

							return video

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

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

							return video_inputs






class   UpperCAmelCase__		(   unittest.TestCase  ):



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






									'''simple docstring'''

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

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



		def        A_		(			self	:     Optional[int]					)      ->    int:






									'''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   UpperCAmelCase__		(   UpperCamelCase ,unittest.TestCase  ):
		lowerCAmelCase_							:						List[Any]							=  TvltImageProcessor if is_vision_available() else None



		def        A_		(			self	:     Any					)      ->    List[Any]:






									'''simple docstring'''

									A    =       TvltImageProcessorTester(self					)



		@property
		def        A_		(			self	:     Dict					)      ->    Optional[int]:






									'''simple docstring'''

									return self.image_processor_tester.prepare_image_processor_dict()



		def        A_		(			self	:     List[str]					)      ->    Union[str, Any]:






									'''simple docstring'''

									A    =       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        A_		(			self	:     Tuple					)      ->    Dict:






									'''simple docstring'''

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






									'''simple docstring'''

									A    =       self.image_processing_class(**self.image_processor_dict					)
									# create random numpy tensors
									A    =       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
									A    =       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
									A    =       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        A_		(			self	:     Any					)      ->    str:






									'''simple docstring'''

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







a					:				Tuple       =      [0.4_85, 0.4_56, 0.4_06]
a					:				Optional[int]       =      [0.2_29, 0.2_24, 0.2_25]
a					:				List[Any]       =      [0.5, 0.5, 0.5]
a					:				Tuple       =      [0.5, 0.5, 0.5]
a					:				Optional[Any]       =      [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]
a					:				int       =      [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]






