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




		"""simple docstring"""





		def __init__(     self							,  lowerCAmelCase__							,  lowerCAmelCase__=7							,  lowerCAmelCase__=3							,  lowerCAmelCase__=1_0							,  lowerCAmelCase__=1_8							,  lowerCAmelCase__=3_0							,  lowerCAmelCase__=4_0_0							,  lowerCAmelCase__=True							,  lowerCAmelCase__=None							,  lowerCAmelCase__=True							,  lowerCAmelCase__=[0.5, 0.5, 0.5]							,  lowerCAmelCase__=[0.5, 0.5, 0.5]							,  lowerCAmelCase__=None							,  ):
				__SCREAMING_SNAKE_CASE            = size if size is not None else {"""shortest_edge""": 1_8}
				__SCREAMING_SNAKE_CASE            = crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

				__SCREAMING_SNAKE_CASE            = parent
				__SCREAMING_SNAKE_CASE            = batch_size
				__SCREAMING_SNAKE_CASE            = num_channels
				__SCREAMING_SNAKE_CASE            = num_frames
				__SCREAMING_SNAKE_CASE            = image_size
				__SCREAMING_SNAKE_CASE            = min_resolution
				__SCREAMING_SNAKE_CASE            = max_resolution
				__SCREAMING_SNAKE_CASE            = do_resize
				__SCREAMING_SNAKE_CASE            = size
				__SCREAMING_SNAKE_CASE            = do_normalize
				__SCREAMING_SNAKE_CASE            = image_mean
				__SCREAMING_SNAKE_CASE            = image_std
				__SCREAMING_SNAKE_CASE            = crop_size




		def 	snake_case_     (     self):
				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 						SCREAMING_SNAKE_CASE_ (						__a     ,				unittest.TestCase ):




		"""simple docstring"""





		__lowercase							:  Union[str, Any]						   =		VivitImageProcessor if is_vision_available() else None




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = VivitImageProcessingTester(self)




		@property
		def 	snake_case_     (     self):
				return self.image_processor_tester.prepare_image_processor_dict()




		def 	snake_case_     (     self):
				__SCREAMING_SNAKE_CASE            = 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):
				__SCREAMING_SNAKE_CASE            = self.image_processing_class.from_dict(self.image_processor_dict)
				self.assertEqual(image_processor.size							,  {"""shortest_edge""": 1_8})
				self.assertEqual(image_processor.crop_size							,  {"""height""": 1_8, """width""": 1_8})

				__SCREAMING_SNAKE_CASE            = self.image_processing_class.from_dict(self.image_processor_dict							,  size=4_2							,  crop_size=8_4)
				self.assertEqual(image_processor.size							,  {"""shortest_edge""": 4_2})
				self.assertEqual(image_processor.crop_size							,  {"""height""": 8_4, """width""": 8_4})




		def 	snake_case_     (     self):
				# Initialize image_processing
				__SCREAMING_SNAKE_CASE            = self.image_processing_class(**self.image_processor_dict)
				# create random PIL videos
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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 	snake_case_     (     self):
				# Initialize image_processing
				__SCREAMING_SNAKE_CASE            = self.image_processing_class(**self.image_processor_dict)
				# create random numpy tensors
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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 	snake_case_     (     self):
				# Initialize image_processing
				__SCREAMING_SNAKE_CASE            = self.image_processing_class(**self.image_processor_dict)
				# create random PyTorch tensors
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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
				__SCREAMING_SNAKE_CASE            = 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"""],
				    )							,  )









'''simple docstring'''


_lowerCamelCase	:       int      	=	"0.21.0"

from .accelerator import Accelerator
from .big_modeling import (
    cpu_offload,
    cpu_offload_with_hook,
    disk_offload,
    dispatch_model,
    init_empty_weights,
    init_on_device,
    load_checkpoint_and_dispatch,
)
from .data_loader import skip_first_batches
from .launchers import debug_launcher, notebook_launcher
from .state import PartialState
from .utils import (
    DeepSpeedPlugin,
    DistributedDataParallelKwargs,
    DistributedType,
    FullyShardedDataParallelPlugin,
    GradScalerKwargs,
    InitProcessGroupKwargs,
    find_executable_batch_size,
    infer_auto_device_map,
    is_rich_available,
    load_checkpoint_in_model,
    synchronize_rng_states,
)


if is_rich_available():
   from .utils import rich

