




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


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import VideoMAEImageProcessor

class    __lowercase							(      unittest.TestCase						):


				'''simple docstring'''


				def __init__( self :  List[str]   ,SCREAMING_SNAKE_CASE_ :  Dict   ,SCREAMING_SNAKE_CASE_ :  str=7   ,SCREAMING_SNAKE_CASE_ :  Union[str, Any]=3   ,SCREAMING_SNAKE_CASE_ :  Tuple=1_0   ,SCREAMING_SNAKE_CASE_ :  Optional[Any]=1_8   ,SCREAMING_SNAKE_CASE_ :  str=3_0   ,SCREAMING_SNAKE_CASE_ :  Any=4_0_0   ,SCREAMING_SNAKE_CASE_ :  Dict=True   ,SCREAMING_SNAKE_CASE_ :  Optional[int]=None   ,SCREAMING_SNAKE_CASE_ :  Optional[int]=True   ,SCREAMING_SNAKE_CASE_ :  Union[str, Any]=[0.5, 0.5, 0.5]   ,SCREAMING_SNAKE_CASE_ :  int=[0.5, 0.5, 0.5]   ,SCREAMING_SNAKE_CASE_ :  List[str]=None   ,):
										snake_case__							:       List[str]				      =       size if size is not None else {'''shortest_edge''': 1_8}
										snake_case__							:       List[str]				      =       crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

										snake_case__							:       Dict				      =       parent
										snake_case__							:       List[Any]				      =       batch_size
										snake_case__							:       Dict				      =       num_channels
										snake_case__							:       Optional[int]				      =       num_frames
										snake_case__							:       List[str]				      =       image_size
										snake_case__							:       List[str]				      =       min_resolution
										snake_case__							:       int				      =       max_resolution
										snake_case__							:       Tuple				      =       do_resize
										snake_case__							:       int				      =       size
										snake_case__							:       int				      =       do_normalize
										snake_case__							:       Dict				      =       image_mean
										snake_case__							:       List[Any]				      =       image_std
										snake_case__							:       Tuple				      =       crop_size





				def    _lowerCamelCase       ( self :  Union[str, Any]   ):
										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    __lowercase							(      snake_case_    , unittest.TestCase						):


				'''simple docstring'''


				_lowerCAmelCase						      =VideoMAEImageProcessor if is_vision_available() else None

				def    _lowerCamelCase       ( self :  List[str]   ):
										snake_case__							:       int				      =       VideoMAEImageProcessingTester(self   )

				@property
				def    _lowerCamelCase       ( self :  str   ):
										return self.image_processor_tester.prepare_image_processor_dict()

				def    _lowerCamelCase       ( self :  Optional[int]   ):
										snake_case__							:       str				      =       self.image_processing_class(**self.image_processor_dict   )
										self.assertTrue(hasattr(_snake_case   ,'''image_mean'''   )   )
										self.assertTrue(hasattr(_snake_case   ,'''image_std'''   )   )
										self.assertTrue(hasattr(_snake_case   ,'''do_normalize'''   )   )
										self.assertTrue(hasattr(_snake_case   ,'''do_resize'''   )   )
										self.assertTrue(hasattr(_snake_case   ,'''do_center_crop'''   )   )
										self.assertTrue(hasattr(_snake_case   ,'''size'''   )   )

				def    _lowerCamelCase       ( self :  int   ):
										snake_case__							:       Optional[int]				      =       self.image_processing_class.from_dict(self.image_processor_dict   )
										self.assertEqual(image_processor.size   ,{'''shortest_edge''': 1_8}   )
										self.assertEqual(image_processor.crop_size   ,{'''height''': 1_8, '''width''': 1_8}   )

										snake_case__							:       Tuple				      =       self.image_processing_class.from_dict(self.image_processor_dict   ,size=4_2   ,crop_size=8_4   )
										self.assertEqual(image_processor.size   ,{'''shortest_edge''': 4_2}   )
										self.assertEqual(image_processor.crop_size   ,{'''height''': 8_4, '''width''': 8_4}   )

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

				def    _lowerCamelCase       ( self :  str   ):
										snake_case__							:       Union[str, Any]				      =       self.image_processing_class(**self.image_processor_dict   )
										# create random PIL videos
										snake_case__							:       List[str]				      =       prepare_video_inputs(self.image_processor_tester   ,equal_resolution=_snake_case   )
										for video in video_inputs:
																self.assertIsInstance(_snake_case   ,_snake_case   )
																self.assertIsInstance(video[0]   ,Image.Image   )

										# Test not batched input
										snake_case__							:       List[Any]				      =       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
										snake_case__							:       Optional[int]				      =       image_processing(_snake_case   ,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 :  Tuple   ):
										snake_case__							:       int				      =       self.image_processing_class(**self.image_processor_dict   )
										# create random numpy tensors
										snake_case__							:       Optional[Any]				      =       prepare_video_inputs(self.image_processor_tester   ,equal_resolution=_snake_case   ,numpify=_snake_case   )
										for video in video_inputs:
																self.assertIsInstance(_snake_case   ,_snake_case   )
																self.assertIsInstance(video[0]   ,np.ndarray   )

										# Test not batched input
										snake_case__							:       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
										snake_case__							:       List[str]				      =       image_processing(_snake_case   ,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[Any]   ):
										snake_case__							:       Optional[int]				      =       self.image_processing_class(**self.image_processor_dict   )
										# create random PyTorch tensors
										snake_case__							:       List[str]				      =       prepare_video_inputs(self.image_processor_tester   ,equal_resolution=_snake_case   ,torchify=_snake_case   )
										for video in video_inputs:
																self.assertIsInstance(_snake_case   ,_snake_case   )
																self.assertIsInstance(video[0]   ,torch.Tensor   )

										# Test not batched input
										snake_case__							:       Any				      =       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
										snake_case__							:       Any				      =       image_processing(_snake_case   ,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		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 9 / 5) + 32  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(float(__A			) + 273.15  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 9 / 5) + 491.67  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) - 32) * 5 / 9  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(((float(__A			) - 32) * 5 / 9) + 273.15  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(float(__A			) + 459.67  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(float(__A			) - 273.15  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(((float(__A			) - 273.15) * 9 / 5) + 32  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 9 / 5)  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) - 491.67) * 5 / 9  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round(float(__A			) - 459.67  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 5 / 9)  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 1.25 + 273.15)  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 2.25 + 32)  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 1.25)  ,							__A			)


def   A		(__A  :       float  ,							__A  :       int = 2			)  -> float:







     """simple docstring"""


     return round((float(__A			) * 2.25 + 32 + 459.67)  ,							__A			)


if __name__ == "__main__":
    import doctest

    doctest.testmod()






