




"""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 VivitImageProcessor






class       lowercase(  unittest.TestCase				):







 '''simple docstring'''





 def __init__(       self:	int,   a_:	Tuple,   a_:	List[Any]=7,   a_:	Tuple=3,   a_:	Dict=10,   a_:	Dict=18,   a_:	Optional[int]=30,   a_:	Dict=400,   a_:	Optional[Any]=True,   a_:	Dict=None,   a_:	int=True,   a_:	Tuple=[0.5, 0.5, 0.5],   a_:	Tuple=[0.5, 0.5, 0.5],   a_:	Optional[int]=None,   ):




   '''simple docstring'''



   _snake_case							:	Any			=						size if size is not None else {"""shortest_edge""": 18}
   _snake_case							:	List[str]			=						crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

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


 def 				UpperCamelCase_     (       self:	int	):




   '''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       lowercase(  __a ,    unittest.TestCase				):







 '''simple docstring'''





 lowercase__				      =      VivitImageProcessor if is_vision_available() else None


 def 				UpperCamelCase_     (       self:	str	):




   '''simple docstring'''



   _snake_case							:	Union[str, Any]			=						VivitImageProcessingTester(self	)


 @property
 def 				UpperCamelCase_     (       self:	int	):




   '''simple docstring'''



   return self.image_processor_tester.prepare_image_processor_dict()


 def 				UpperCamelCase_     (       self:	int	):




   '''simple docstring'''



   _snake_case							:	Tuple			=						self.image_processing_class(**self.image_processor_dict	)
   self.assertTrue(hasattr(a_,   """image_mean"""	)	)
   self.assertTrue(hasattr(a_,   """image_std"""	)	)
   self.assertTrue(hasattr(a_,   """do_normalize"""	)	)
   self.assertTrue(hasattr(a_,   """do_resize"""	)	)
   self.assertTrue(hasattr(a_,   """do_center_crop"""	)	)
   self.assertTrue(hasattr(a_,   """size"""	)	)


 def 				UpperCamelCase_     (       self:	List[str]	):




   '''simple docstring'''



   _snake_case							:	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}	)

   _snake_case							:	List[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:	Dict	):




   '''simple docstring'''



   _snake_case							:	Optional[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=a_	)
   for video in video_inputs:
     self.assertIsInstance(a_,   a_	)
     self.assertIsInstance(video[0],   Image.Image	)

   # Test not batched input
   _snake_case							:	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
   _snake_case							:	Dict			=						image_processing(a_,   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	):




   '''simple docstring'''



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

   # Test not batched input
   _snake_case							:	Dict			=						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[Any]			=						image_processing(a_,   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:	Tuple	):




   '''simple docstring'''



   _snake_case							:	Dict			=						self.image_processing_class(**self.image_processor_dict	)
   # create random PyTorch tensors
   _snake_case							:	str			=						prepare_video_inputs(self.image_processor_tester,   equal_resolution=a_,   torchify=a_	)
   for video in video_inputs:
     self.assertIsInstance(a_,   a_	)
     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							:	Union[str, Any]			=						image_processing(a_,   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"""],
       ),   )








"""simple docstring"""


from ...processing_utils import ProcessorMixin






class       lowercase(  __a				):







 '''simple docstring'''





 lowercase__				      =      ["image_processor", "feature_extractor"]
 lowercase__				      =      "TvltImageProcessor"
 lowercase__				      =      "TvltFeatureExtractor"


 def __init__(       self:	Dict,   a_:	Union[str, Any],   a_:	Union[str, Any]	):




   '''simple docstring'''



   super().__init__(image_processor=a_,   feature_extractor=a_	)

   _snake_case							:	Any			=						image_processor
   _snake_case							:	Dict			=						feature_extractor


 def __call__(       self:	int,   a_:	str=None,   a_:	Tuple=None,   a_:	Dict=None,   a_:	str=None,   a_:	Optional[int]=False,   a_:	Tuple=False,   *a_:	List[str],   **a_:	int,   ):




   '''simple docstring'''



   if images is None and audio is None:
     raise ValueError("""You need to specify either an `images` or `audio` input to process."""	)

   _snake_case							:	Optional[int]			=						None
   if images is not None:
     _snake_case							:	Tuple			=						self.image_processor(a_,   mask_pixel=a_,   *a_,   **a_	)
   if images_mixed is not None:
     _snake_case							:	Optional[int]			=						self.image_processor(a_,   is_mixed=a_,   *a_,   **a_	)
   if audio is not None:
     _snake_case							:	Any			=						self.feature_extractor(
         a_,   *a_,   sampling_rate=a_,   mask_audio=a_,   **a_	)

   _snake_case							:	List[str]			=						{}
   if audio is not None:
     output_dict.update(a_	)
   if images is not None:
     output_dict.update(a_	)
   if images_mixed_dict is not None:
     output_dict.update(a_	)
   return output_dict


 @property
 def 				UpperCamelCase_     (       self:	List[str]	):




   '''simple docstring'''



   _snake_case							:	Dict			=						self.image_processor.model_input_names
   _snake_case							:	List[str]			=						self.feature_extractor.model_input_names
   return list(dict.fromkeys(image_processor_input_names + feature_extractor_input_names	)	)


