




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, prepare_video_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import VideoMAEImageProcessor





class 		A__    (       unittest.TestCase			):






	def __init__(     self    ,					lowerCamelCase    ,					lowerCamelCase=7    ,					lowerCamelCase=3    ,					lowerCamelCase=10    ,					lowerCamelCase=18    ,					lowerCamelCase=30    ,					lowerCamelCase=400    ,					lowerCamelCase=True    ,					lowerCamelCase=None    ,					lowerCamelCase=True    ,					lowerCamelCase=[0.5, 0.5, 0.5]    ,					lowerCamelCase=[0.5, 0.5, 0.5]    ,					lowerCamelCase=None    ,					)				->       Optional[Any]:




						"""simple docstring"""






						__magic_name__ :							Union[str, Any]		       =							size if size is not None else {'''shortest_edge''': 18}
						__magic_name__ :							Optional[int]		       =							crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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






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




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





@require_torch
@require_vision
class 		A__    (       __SCREAMING_SNAKE_CASE		,					unittest.TestCase			):
	lowerCamelCase__		:			Tuple       =VideoMAEImageProcessor if is_vision_available() else None






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




						"""simple docstring"""






						__magic_name__ :							Optional[int]		       =							VideoMAEImageProcessingTester(self						)






	@property
	def 			lowercase				(     self						)				->       List[Any]:




						"""simple docstring"""






						return self.image_processor_tester.prepare_image_processor_dict()






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




						"""simple docstring"""






						__magic_name__ :							Tuple		       =							self.image_processing_class(**self.image_processor_dict						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''image_mean'''						)						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''image_std'''						)						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''do_normalize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''do_resize'''						)						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''do_center_crop'''						)						)
						self.assertTrue(hasattr(lowerCamelCase    ,					'''size'''						)						)






	def 			lowercase				(     self						)				->       Tuple:




						"""simple docstring"""






						__magic_name__ :							str		       =							self.image_processing_class.from_dict(self.image_processor_dict						)
						self.assertEqual(image_processor.size    ,					{'''shortest_edge''': 18}						)
						self.assertEqual(image_processor.crop_size    ,					{'''height''': 18, '''width''': 18}						)

						__magic_name__ :							Any		       =							self.image_processing_class.from_dict(self.image_processor_dict    ,					size=42    ,					crop_size=84						)
						self.assertEqual(image_processor.size    ,					{'''shortest_edge''': 42}						)
						self.assertEqual(image_processor.crop_size    ,					{'''height''': 84, '''width''': 84}						)






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




						"""simple docstring"""






						pass






	def 			lowercase				(     self						)				->       str:




						"""simple docstring"""






						__magic_name__ :							Dict		       =							self.image_processing_class(**self.image_processor_dict						)
						# create random PIL videos
						__magic_name__ :							Optional[int]		       =							prepare_video_inputs(self.image_processor_tester    ,					equal_resolution=lowerCamelCase						)
						for video in video_inputs:
											self.assertIsInstance(lowerCamelCase    ,					lowerCamelCase						)
											self.assertIsInstance(video[0]    ,					Image.Image						)

						# Test not batched input
						__magic_name__ :							Tuple		       =							image_processing(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
						__magic_name__ :							Optional[Any]		       =							image_processing(lowerCamelCase    ,					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 			lowercase				(     self						)				->       List[str]:




						"""simple docstring"""






						__magic_name__ :							Tuple		       =							self.image_processing_class(**self.image_processor_dict						)
						# create random numpy tensors
						__magic_name__ :							Optional[Any]		       =							prepare_video_inputs(self.image_processor_tester    ,					equal_resolution=lowerCamelCase    ,					numpify=lowerCamelCase						)
						for video in video_inputs:
											self.assertIsInstance(lowerCamelCase    ,					lowerCamelCase						)
											self.assertIsInstance(video[0]    ,					np.ndarray						)

						# Test not batched input
						__magic_name__ :							Optional[int]		       =							image_processing(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
						__magic_name__ :							Optional[int]		       =							image_processing(lowerCamelCase    ,					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 			lowercase				(     self						)				->       Optional[Any]:




						"""simple docstring"""






						__magic_name__ :							Dict		       =							self.image_processing_class(**self.image_processor_dict						)
						# create random PyTorch tensors
						__magic_name__ :							Any		       =							prepare_video_inputs(self.image_processor_tester    ,					equal_resolution=lowerCamelCase    ,					torchify=lowerCamelCase						)
						for video in video_inputs:
											self.assertIsInstance(lowerCamelCase    ,					lowerCamelCase						)
											self.assertIsInstance(video[0]    ,					torch.Tensor						)

						# Test not batched input
						__magic_name__ :							str		       =							image_processing(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
						__magic_name__ :							List[Any]		       =							image_processing(lowerCamelCase    ,					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 ..utils import requires_backends


lowercase_		=							None





class 		A__    :






	def __init__(     self    ,					*lowerCamelCase    ,					**lowerCamelCase						)				->       Optional[Any]:




						"""simple docstring"""






						requires_backends(self    ,					['''detectron2''']						)






	@classmethod
	def 			lowercase				(     cls    ,					*lowerCamelCase    ,					**lowerCamelCase						)				->       List[Any]:




						"""simple docstring"""






						requires_backends(cls    ,					['''detectron2''']						)



