


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							,					)   ->							Union[str, Any]:




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

        lowercase__:  int         =  parent
        lowercase__:  Any         =  batch_size
        lowercase__:  Optional[int]         =  num_channels
        lowercase__:  str         =  num_frames
        lowercase__:  List[Any]         =  image_size
        lowercase__:  Tuple         =  min_resolution
        lowercase__:  Tuple         =  max_resolution
        lowercase__:  int         =  do_resize
        lowercase__:  Optional[int]         =  size
        lowercase__:  List[Any]         =  do_normalize
        lowercase__:  str         =  image_mean
        lowercase__:  Dict         =  image_std
        lowercase__:  Tuple         =  crop_size
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							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,
            "crop_size": self.crop_size,
        }





@require_torch
@require_vision
class     __a     (       __UpperCamelCase			,			unittest.TestCase ):
 __lowercase					:				Tuple  	=					VideoMAEImageProcessor if is_vision_available() else None
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							int:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  VideoMAEImageProcessingTester(self					)
 @property
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Tuple:




        '''simple docstring'''
        return self.image_processor_tester.prepare_image_processor_dict()
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Any:




        '''simple docstring'''
        lowercase__:  str         =  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 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  List[Any]         =  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}					)

        lowercase__:  str         =  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 						SCREAMING_SNAKE_CASE__  (  self					)   ->							str:




        '''simple docstring'''
        pass
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        # Initialize image_processing
        lowercase__:  Optional[int]         =  self.image_processing_class(**self.image_processor_dict					)
        # create random PIL videos
        lowercase__:  Optional[Any]         =  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
        lowercase__:  Optional[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
        lowercase__:  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'],
            )							,					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							str:




        '''simple docstring'''
        # Initialize image_processing
        lowercase__:  Union[str, Any]         =  self.image_processing_class(**self.image_processor_dict					)
        # create random numpy tensors
        lowercase__:  Optional[int]         =  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
        lowercase__:  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
        lowercase__:  Dict         =  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 						SCREAMING_SNAKE_CASE__  (  self					)   ->							int:




        '''simple docstring'''
        # Initialize image_processing
        lowercase__:  Any         =  self.image_processing_class(**self.image_processor_dict					)
        # create random PyTorch tensors
        lowercase__:  int         =  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
        lowercase__:  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
        lowercase__:  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'],
            )							,					)






from typing import Callable




def   snake_case_	(    snake_case	)    ->							Tuple:

       def wrapper(snake_case	):
              lowercase__:  Tuple         =  function_with_docstring.__doc__
              return target_function

       return wrapper


