




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 						__lowerCAmelCase      (      unittest.TestCase					):
							def __init__(		self		:List[str]						, __magic_name__		:Any						, __magic_name__		:Any=7						, __magic_name__		:Any=3						, __magic_name__		:Optional[int]=10						, __magic_name__		:str=18						, __magic_name__		:Dict=30						, __magic_name__		:Any=400						, __magic_name__		:Optional[int]=True						, __magic_name__		:Union[str, Any]=None						, __magic_name__		:List[str]=True						, __magic_name__		:int=[0.5, 0.5, 0.5]						, __magic_name__		:Tuple=[0.5, 0.5, 0.5]						, __magic_name__		:str=None						, ):







								'''simple docstring'''







								a									=				size if size is not None else {"""shortest_edge""": 18}
								a									=				crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

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





							def  lowerCamelCase__				(		self		:Tuple							):







								'''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 						__lowerCAmelCase      (      __magic_name__ ,			unittest.TestCase					):
							UpperCamelCase__   	=    VivitImageProcessor if is_vision_available() else None
							def  lowerCamelCase__				(		self		:List[str]							):







								'''simple docstring'''







								a									=				VivitImageProcessingTester(self							)
							@property
							def  lowerCamelCase__				(		self		:Any							):







								'''simple docstring'''







								return self.image_processor_tester.prepare_image_processor_dict()
							def  lowerCamelCase__				(		self		:Union[str, Any]							):







								'''simple docstring'''







								a									=				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  lowerCamelCase__				(		self		:str							):







								'''simple docstring'''







								a									=				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}							)

								a									=				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  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								a									=				self.image_processing_class(**self.image_processor_dict							)
								# create random PIL videos
								a									=				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
								a									=				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
								a									=				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  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								a									=				self.image_processing_class(**self.image_processor_dict							)
								# create random numpy tensors
								a									=				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
								a									=				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
								a									=				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  lowerCamelCase__				(		self		:int							):







								'''simple docstring'''







								a									=				self.image_processing_class(**self.image_processor_dict							)
								# create random PyTorch tensors
								a									=				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
								a									=				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
								a									=				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"""],
								    )						, )







import warnings

from ...utils import logging
from .image_processing_layoutlmva import LayoutLMvaImageProcessor


__UpperCamelCase   :			Optional[int]          = logging.get_logger(__name__)

class 						__lowerCAmelCase      (      __magic_name__					):
							def __init__(		self		:Union[str, Any]						, *__magic_name__		:int						, **__magic_name__		:str							):







								'''simple docstring'''







								warnings.warn(
								    """The class LayoutLMv2FeatureExtractor is deprecated and will be removed in version 5 of Transformers."""
								    """ Please use LayoutLMv2ImageProcessor instead."""						, __magic_name__						, )
								super().__init__(*__magic_name__						, **__magic_name__							)

