






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        snake_case_					(						unittest.TestCase			):

      """simple docstring"""



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




           '''simple docstring'''



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

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



      def 					UpperCAmelCase__				(self:				Dict      )						->    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        snake_case_					(						a__		,       unittest.TestCase			):

      """simple docstring"""



      snake_case__   					=			VideoMAEImageProcessor if is_vision_available() else None



      def 					UpperCAmelCase__				(self:				Dict      )						->    Dict:




           '''simple docstring'''



           __a				:	Any			=				VideoMAEImageProcessingTester(self      )



      @property
      def 					UpperCAmelCase__				(self:				Optional[int]      )						->    List[str]:




           '''simple docstring'''



           return self.image_processor_tester.prepare_image_processor_dict()



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




           '''simple docstring'''



           __a				:	Optional[Any]			=				self.image_processing_class(**self.image_processor_dict      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"image_mean"      )      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"image_std"      )      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"do_normalize"      )      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"do_resize"      )      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"do_center_crop"      )      )
           self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_   ,				"size"      )      )



      def 					UpperCAmelCase__				(self:				List[Any]      )						->    int:




           '''simple docstring'''



           __a				:	Tuple			=				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}      )

           __a				:	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 					UpperCAmelCase__				(self:				List[str]      )						->    Union[str, Any]:




           '''simple docstring'''



           pass



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




           '''simple docstring'''



           __a				:	List[Any]			=				self.image_processing_class(**self.image_processor_dict      )
           # create random PIL videos
           __a				:	Dict			=				prepare_video_inputs(self.image_processor_tester   ,				equal_resolution=SCREAMING_SNAKE_CASE_      )
           for video in video_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_      )
                self.assertIsInstance(video[0]   ,				Image.Image      )

           # Test not batched input
           __a				:	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
           __a				:	str			=				image_processing(SCREAMING_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 					UpperCAmelCase__				(self:				Dict      )						->    Dict:




           '''simple docstring'''



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

           # Test not batched input
           __a				:	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
           __a				:	Optional[Any]			=				image_processing(SCREAMING_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 					UpperCAmelCase__				(self:				str      )						->    Optional[Any]:




           '''simple docstring'''



           __a				:	List[Any]			=				self.image_processing_class(**self.image_processor_dict      )
           # create random PyTorch tensors
           __a				:	Optional[int]			=				prepare_video_inputs(self.image_processor_tester   ,				equal_resolution=SCREAMING_SNAKE_CASE_   ,				torchify=SCREAMING_SNAKE_CASE_      )
           for video in video_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE_   ,				SCREAMING_SNAKE_CASE_      )
                self.assertIsInstance(video[0]   ,				torch.Tensor      )

           # Test not batched input
           __a				:	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
           __a				:	Optional[Any]			=				image_processing(SCREAMING_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"],
               )   ,				)













import warnings

from .generation import GenerationMixin




class        snake_case_					(						__UpperCamelCase			):

						"""simple docstring"""



						warnings.warn(
						    """Importing `GenerationMixin` from `src/transformers/generation_utils.py` is deprecated and will """
						    """be removed in Transformers v5. Import as `from transformers import GenerationMixin` instead."""		,       __UpperCamelCase		,       )





