





'''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


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import TvltImageProcessor



def 						__A						(       lowerCamelCase_	,	lowerCamelCase_=10	,	lowerCamelCase_=10	,	lowerCamelCase_=False	,	lowerCamelCase_=False					):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE				:							Optional[int]						=	[]
		for i in range(image_processor_tester.num_frames					):
				video.append(np.random.randint(2_55	,	size=(image_processor_tester.num_channels, width, height)	,	dtype=np.uinta					)					)

		if not numpify and not torchify:
				# PIL expects the channel dimension as last dimension
				SCREAMING_SNAKE_CASE				:							Optional[int]						=	[Image.fromarray(np.moveaxis(__lowercase	,	0	,	-1					)					) for frame in video]

		if torchify:
				SCREAMING_SNAKE_CASE				:							List[str]						=	[torch.from_numpy(__lowercase					) for frame in video]

		return video



def 						__A						(       lowerCamelCase_	,	lowerCamelCase_=False	,	lowerCamelCase_=False	,	lowerCamelCase_=False					):


		"""simple docstring"""



		assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

		SCREAMING_SNAKE_CASE				:							List[str]						=	[]
		for i in range(image_processor_tester.batch_size					):
				if equal_resolution:
						SCREAMING_SNAKE_CASE				:							Optional[Any]						=	image_processor_tester.max_resolution
				else:
						SCREAMING_SNAKE_CASE,    SCREAMING_SNAKE_CASE				:							Tuple						=	np.random.choice(
						    np.arange(image_processor_tester.min_resolution	,	image_processor_tester.max_resolution					)	,	2					)
						SCREAMING_SNAKE_CASE				:							Tuple						=	prepare_video(
						    image_processor_tester=__lowercase	,	width=__lowercase	,	height=__lowercase	,	numpify=__lowercase	,	torchify=__lowercase	,	)
				video_inputs.append(__lowercase					)

		return video_inputs




class       UpperCamelCase__			(			unittest.TestCase	):




					"""simple docstring"""


					def __init__(		self							:	List[Any]     ,		lowerCamelCase_							:	List[str]     ,		lowerCamelCase_							:	Tuple=7     ,		lowerCamelCase_							:	Optional[Any]=3     ,		lowerCamelCase_							:	Any=4     ,		lowerCamelCase_							:	List[Any]=18     ,		lowerCamelCase_							:	Dict=30     ,		lowerCamelCase_							:	str=4_00     ,		lowerCamelCase_							:	Dict=True     ,		lowerCamelCase_							:	Optional[Any]=None     ,		lowerCamelCase_							:	Tuple=True     ,		lowerCamelCase_							:	Optional[int]=[0.5, 0.5, 0.5]     ,		lowerCamelCase_							:	Union[str, Any]=[0.5, 0.5, 0.5]     ,		lowerCamelCase_							:	Optional[Any]=True     ,		lowerCamelCase_							:	str=None     ,		):

							'''simple docstring'''



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

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



					def lowerCamelCase_	(		self							:	Optional[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,
							    "do_center_crop": self.do_center_crop,
							    "crop_size": self.crop_size,
							}







@require_torch
@require_vision
class       UpperCamelCase__			(			lowercase_		,			unittest.TestCase	):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__						=					TvltImageProcessor if is_vision_available() else None


					def lowerCamelCase_	(		self							:	Tuple		):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE				:							Optional[int]						=	TvltImageProcessorTester(self		)


					@property
					def lowerCamelCase_	(		self							:	Optional[Any]		):

							'''simple docstring'''



							return self.image_processor_tester.prepare_image_processor_dict()


					def lowerCamelCase_	(		self							:	Tuple		):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	self.image_processing_class(**self.image_processor_dict		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""image_mean"""		)		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""image_std"""		)		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""do_normalize"""		)		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""do_resize"""		)		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""do_center_crop"""		)		)
							self.assertTrue(hasattr(UpperCamelCase_     ,		"""size"""		)		)


					def lowerCamelCase_	(		self							:	Tuple		):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE				:							List[Any]						=	self.image_processing_class(**self.image_processor_dict		)
							# create random PIL videos
							SCREAMING_SNAKE_CASE				:							List[Any]						=	prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=UpperCamelCase_		)
							for video in video_inputs:
									self.assertIsInstance(UpperCamelCase_     ,		UpperCamelCase_		)
									self.assertIsInstance(video[0]     ,		Image.Image		)

							# Test not batched input
							SCREAMING_SNAKE_CASE				:							Any						=	image_processor(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				:							Optional[int]						=	image_processor(UpperCamelCase_     ,		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							:	Optional[Any]		):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE				:							int						=	self.image_processing_class(**self.image_processor_dict		)
							# create random numpy tensors
							SCREAMING_SNAKE_CASE				:							Optional[int]						=	prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=UpperCamelCase_     ,		numpify=UpperCamelCase_		)
							for video in video_inputs:
									self.assertIsInstance(UpperCamelCase_     ,		UpperCamelCase_		)
									self.assertIsInstance(video[0]     ,		np.ndarray		)

							# Test not batched input
							SCREAMING_SNAKE_CASE				:							Dict						=	image_processor(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				:							int						=	image_processor(UpperCamelCase_     ,		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'''



							SCREAMING_SNAKE_CASE				:							Union[str, Any]						=	self.image_processing_class(**self.image_processor_dict		)
							# create random PyTorch tensors
							SCREAMING_SNAKE_CASE				:							int						=	prepare_video_inputs(self.image_processor_tester     ,		equal_resolution=UpperCamelCase_     ,		torchify=UpperCamelCase_		)
							for video in video_inputs:
									self.assertIsInstance(UpperCamelCase_     ,		UpperCamelCase_		)
									self.assertIsInstance(video[0]     ,		torch.Tensor		)

							# Test not batched input
							SCREAMING_SNAKE_CASE				:							Dict						=	image_processor(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				:							Tuple						=	image_processor(UpperCamelCase_     ,		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'''




import warnings

from ...utils import logging
from .image_processing_detr import DetrImageProcessor


__UpperCAmelCase         =   logging.get_logger(__name__)




class       UpperCamelCase__			(			lowercase_	):




					"""simple docstring"""


					def __init__(		self							:	Dict     ,		*lowerCamelCase_							:	Optional[int]     ,		**lowerCamelCase_							:	Optional[int]		):

							'''simple docstring'''



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



