code: 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 SCREAMING_SNAKE_CASE				(     lowercase_:	Tuple		,						lowercase_:	Optional[int]=10		,						lowercase_:	Optional[Any]=10		,						lowercase_:	Optional[Any]=False		,						lowercase_:	Any=False				):
         _UpperCamelCase     :       List[Any]  						=  []
         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
                _UpperCamelCase     :       Tuple  						=  [Image.fromarray(np.moveaxis(lowercase_		,						0		,						-1				)				) for frame in video]
  
         if torchify:
                _UpperCamelCase     :       Union[str, Any]  						=  [torch.from_numpy(lowercase_				) for frame in video]
  
         return video
  
  
  def SCREAMING_SNAKE_CASE				(     lowercase_:	List[str]		,						lowercase_:	Optional[Any]=False		,						lowercase_:	Tuple=False		,						lowercase_:	Union[str, Any]=False				):
         assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"
  
         _UpperCamelCase     :       Any  						=  []
         for i in range(image_processor_tester.batch_size				):
                if equal_resolution:
                       _UpperCamelCase     :       str  						=  image_processor_tester.max_resolution
                else:
                       _UpperCamelCase						,      _UpperCamelCase     :       int  						=  np.random.choice(
                           np.arange(image_processor_tester.min_resolution		,						image_processor_tester.max_resolution				)		,						2				)
                       _UpperCamelCase     :       Optional[Any]  						=  prepare_video(
                           image_processor_tester=lowercase_		,						width=lowercase_		,						height=lowercase_		,						numpify=lowercase_		,						torchify=lowercase_		,						)
                video_inputs.append(lowercase_				)
  
         return video_inputs
  
  
  
  
  class    __lowerCAmelCase  (       unittest.TestCase						):
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		Optional[Any]       ,			lowerCamelCase       :		Union[str, Any]       ,			lowerCamelCase       :		Optional[int]=7       ,			lowerCamelCase       :		List[Any]=3       ,			lowerCamelCase       :		str=4       ,			lowerCamelCase       :		Union[str, Any]=1_8       ,			lowerCamelCase       :		str=3_0       ,			lowerCamelCase       :		List[str]=4_0_0       ,			lowerCamelCase       :		Tuple=True       ,			lowerCamelCase       :		Union[str, Any]=None       ,			lowerCamelCase       :		List[str]=True       ,			lowerCamelCase       :		Optional[Any]=[0.5, 0.5, 0.5]       ,			lowerCamelCase       :		Any=[0.5, 0.5, 0.5]       ,			lowerCamelCase       :		str=True       ,			lowerCamelCase       :		Optional[Any]=None       ,			) ->							Union[str, Any]:
          _UpperCamelCase     :       Optional[int]  						=  size if size is not None else {'shortest_edge': 1_8}
          _UpperCamelCase     :       Dict  						=  crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
  
          _UpperCamelCase     :       Any  						=  parent
          _UpperCamelCase     :       Optional[Any]  						=  batch_size
          _UpperCamelCase     :       List[Any]  						=  num_channels
          _UpperCamelCase     :       List[Any]  						=  num_frames
          _UpperCamelCase     :       Union[str, Any]  						=  image_size
          _UpperCamelCase     :       Dict  						=  min_resolution
          _UpperCamelCase     :       int  						=  max_resolution
          _UpperCamelCase     :       Union[str, Any]  						=  do_resize
          _UpperCamelCase     :       str  						=  size
          _UpperCamelCase     :       Dict  						=  do_normalize
          _UpperCamelCase     :       Union[str, Any]  						=  image_mean
          _UpperCamelCase     :       Optional[int]  						=  image_std
          _UpperCamelCase     :       Tuple  						=  do_center_crop
          _UpperCamelCase     :       Any  						=  crop_size
  
   def 					__snake_case					(			self       :		Tuple  ) ->							Optional[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,
              "do_center_crop": self.do_center_crop,
              "crop_size": self.crop_size,
          }
  
  
  
  
  
  
  
  @require_torch
  @require_vision
  class    __lowerCAmelCase  (       a_,	unittest.TestCase						):
  
  
  
   '''simple docstring'''
   _lowerCamelCase						:	Any				    = TvltImageProcessor if is_vision_available() else None
  
   def 					__snake_case					(			self       :		int  ) ->							Optional[int]:
          _UpperCamelCase     :       Optional[Any]  						=  TvltImageProcessorTester(self  )
  
   @property
   def 					__snake_case					(			self       :		Optional[Any]  ) ->							Any:
          return self.image_processor_tester.prepare_image_processor_dict()
  
   def 					__snake_case					(			self       :		Union[str, Any]  ) ->							str:
          _UpperCamelCase     :       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 					__snake_case					(			self       :		Dict  ) ->							Optional[int]:
          # Initialize image_processor
          _UpperCamelCase     :       str  						=  self.image_processing_class(**self.image_processor_dict  )
          # create random PIL videos
          _UpperCamelCase     :       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
          _UpperCamelCase     :       Dict  						=  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
          _UpperCamelCase     :       Any  						=  image_processor(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 					__snake_case					(			self       :		Union[str, Any]  ) ->							List[str]:
          # Initialize image_processor
          _UpperCamelCase     :       Optional[int]  						=  self.image_processing_class(**self.image_processor_dict  )
          # create random numpy tensors
          _UpperCamelCase     :       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
          _UpperCamelCase     :       Optional[int]  						=  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
          _UpperCamelCase     :       int  						=  image_processor(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 					__snake_case					(			self       :		Optional[Any]  ) ->							Any:
          # Initialize image_processor
          _UpperCamelCase     :       int  						=  self.image_processing_class(**self.image_processor_dict  )
          # create random PyTorch tensors
          _UpperCamelCase     :       Optional[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
          _UpperCamelCase     :       Dict  						=  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
          _UpperCamelCase     :       Optional[int]  						=  image_processor(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'],
              )       ,			)
  
  
  
  
style_context: from ..utils import requires_backends
  
  
  UpperCAmelCase					=				None
  
  
  
  
  class    __lowerCAmelCase  :
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		Optional[int]       ,			*lowerCamelCase       :		Dict       ,			**lowerCamelCase       :		int  ) ->							Tuple:
          requires_backends(self       ,			['detectron2']  )
  
   @classmethod
   def 					__snake_case					(			cls       :		Optional[Any]       ,			*lowerCamelCase       :		Optional[int]       ,			**lowerCamelCase       :		Tuple  ) ->							List[str]:
          requires_backends(cls       ,			['detectron2']  )
  
  
  
  