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




				def __init__(							self	:				str,    SCREAMING_SNAKE_CASE_	:				str,    SCREAMING_SNAKE_CASE_	:				List[Any]=7,    SCREAMING_SNAKE_CASE_	:				Optional[Any]=3,    SCREAMING_SNAKE_CASE_	:				Optional[Any]=10,    SCREAMING_SNAKE_CASE_	:				Optional[Any]=18,    SCREAMING_SNAKE_CASE_	:				Optional[int]=30,    SCREAMING_SNAKE_CASE_	:				List[str]=4_00,    SCREAMING_SNAKE_CASE_	:				List[Any]=True,    SCREAMING_SNAKE_CASE_	:				Optional[Any]=None,    SCREAMING_SNAKE_CASE_	:				Dict=True,    SCREAMING_SNAKE_CASE_	:				List[Any]=[0.5, 0.5, 0.5],    SCREAMING_SNAKE_CASE_	:				List[str]=[0.5, 0.5, 0.5],    SCREAMING_SNAKE_CASE_	:				Dict=None,    ):
										snake_case       :     List[Any] =    size if size is not None else {'''shortest_edge''': 18}
										snake_case       :     Union[str, Any] =    crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

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




				def 	__snake_case							(							self	:				Dict      ):
										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 						a   (				__magic_name__				,unittest.TestCase    ):
				_snake_case		    = VivitImageProcessor if is_vision_available() else None




				def 	__snake_case							(							self	:				Optional[Any]      ):
										snake_case       :     int =    VivitImageProcessingTester(self      )




				@property
				def 	__snake_case							(							self	:				Optional[Any]      ):
										return self.image_processor_tester.prepare_image_processor_dict()




				def 	__snake_case							(							self	:				List[str]      ):
										snake_case       :     Union[str, 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 	__snake_case							(							self	:				Optional[int]      ):
										snake_case       :     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}      )

										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 	__snake_case							(							self	:				Optional[int]      ):
										# Initialize image_processing
										snake_case       :     int =    self.image_processing_class(**self.image_processor_dict      )
										# create random PIL videos
										snake_case       :     Union[str, Any] =    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
										snake_case       :     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
										snake_case       :     Dict =    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 	__snake_case							(							self	:				str      ):
										# Initialize image_processing
										snake_case       :     Union[str, Any] =    self.image_processing_class(**self.image_processor_dict      )
										# create random numpy tensors
										snake_case       :     List[str] =    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
										snake_case       :     List[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
										snake_case       :     Union[str, 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 	__snake_case							(							self	:				Dict      ):
										# Initialize image_processing
										snake_case       :     Union[str, Any] =    self.image_processing_class(**self.image_processor_dict      )
										# create random PyTorch tensors
										snake_case       :     Optional[Any] =    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
										snake_case       :     List[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
										snake_case       :     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'''],
										    ),    )



'''simple docstring'''





from .testing import (
    are_the_same_tensors,
    execute_subprocess_async,
    require_bnb,
    require_cpu,
    require_cuda,
    require_huggingface_suite,
    require_mps,
    require_multi_gpu,
    require_multi_xpu,
    require_safetensors,
    require_single_gpu,
    require_single_xpu,
    require_torch_min_version,
    require_tpu,
    require_xpu,
    skip,
    slow,
)
from .training import RegressionDataset, RegressionModel, RegressionModelaXPU


from .scripts import test_script, test_sync, test_ops  # isort: skip

