





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,		__magic_name__,		__magic_name__=7,		__magic_name__=3,		__magic_name__=10,		__magic_name__=18,		__magic_name__=30,		__magic_name__=400,		__magic_name__=True,		__magic_name__=None,		__magic_name__=True,		__magic_name__=[0.5, 0.5, 0.5],		__magic_name__=[0.5, 0.5, 0.5],		__magic_name__=None,		) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[int]          =      size if size is not None else {'''shortest_edge''': 18}
       UpperCamelCase__							:				str          =      crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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




   def       UpperCamelCase__  (    self							) ->      Any:






       """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__       (	__lowerCamelCase			,				unittest.TestCase				):

   '''simple docstring'''


   a						:							str   		=		VivitImageProcessor if is_vision_available() else None




   def       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				str          =      VivitImageProcessingTester(self							)




   @property
   def       UpperCamelCase__  (    self							) ->      List[str]:






       """simple docstring"""
       return self.image_processor_tester.prepare_image_processor_dict()




   def       UpperCamelCase__  (    self							) ->      Any:






       """simple docstring"""
       UpperCamelCase__							:				Union[str, Any]          =      self.image_processing_class(**self.image_processor_dict							)
       self.assertTrue(hasattr(__magic_name__,		'''image_mean'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''image_std'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''do_normalize'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''do_resize'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''do_center_crop'''							)							)
       self.assertTrue(hasattr(__magic_name__,		'''size'''							)							)




   def       UpperCamelCase__  (    self							) ->      Dict:






       """simple docstring"""
       UpperCamelCase__							:				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}							)

       UpperCamelCase__							:				List[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       UpperCamelCase__  (    self							) ->      List[Any]:






       """simple docstring"""
       UpperCamelCase__							:				Optional[Any]          =      self.image_processing_class(**self.image_processor_dict							)
       # create random PIL videos
       UpperCamelCase__							:				Optional[int]          =      prepare_video_inputs(self.image_processor_tester,		equal_resolution=__magic_name__							)
       for video in video_inputs:
           self.assertIsInstance(__magic_name__,		__magic_name__							)
           self.assertIsInstance(video[0],		Image.Image							)

       # Test not batched input
       UpperCamelCase__							:				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
       UpperCamelCase__							:				Any          =      image_processing(__magic_name__,		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:






       """simple docstring"""
       UpperCamelCase__							:				Any          =      self.image_processing_class(**self.image_processor_dict							)
       # create random numpy tensors
       UpperCamelCase__							:				Dict          =      prepare_video_inputs(self.image_processor_tester,		equal_resolution=__magic_name__,		numpify=__magic_name__							)
       for video in video_inputs:
           self.assertIsInstance(__magic_name__,		__magic_name__							)
           self.assertIsInstance(video[0],		np.ndarray							)

       # Test not batched input
       UpperCamelCase__							:				Union[str, 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
       UpperCamelCase__							:				Dict          =      image_processing(__magic_name__,		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							) ->      Union[str, Any]:






       """simple docstring"""
       UpperCamelCase__							:				List[str]          =      self.image_processing_class(**self.image_processor_dict							)
       # create random PyTorch tensors
       UpperCamelCase__							:				str          =      prepare_video_inputs(self.image_processor_tester,		equal_resolution=__magic_name__,		torchify=__magic_name__							)
       for video in video_inputs:
           self.assertIsInstance(__magic_name__,		__magic_name__							)
           self.assertIsInstance(video[0],		torch.Tensor							)

       # Test not batched input
       UpperCamelCase__							:				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
       UpperCamelCase__							:				Optional[Any]          =      image_processing(__magic_name__,		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'''

a_  :				str						= """
# Transformers installation
! pip install transformers datasets
# To install from source instead of the last release, comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/transformers.git
"""

a_  :				Any						= [{"""type""": """code""", """content""": INSTALL_CONTENT}]
a_  :				int						= {
    """{processor_class}""": """FakeProcessorClass""",
    """{model_class}""": """FakeModelClass""",
    """{object_class}""": """FakeObjectClass""",
}



