






'''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 						__magic_name__(			_A    ,   _A=10    ,   _A=10    ,   _A=False    ,   _A=False       ):
						'''simple docstring'''





						UpperCamelCase__       =			[]
						for i in range(image_processor_tester.num_frames       ):
												video.append(np.random.randint(255    ,   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
												UpperCamelCase__       =			[Image.fromarray(np.moveaxis(_A    ,   0    ,   -1       )       ) for frame in video]

						if torchify:
												UpperCamelCase__       =			[torch.from_numpy(_A       ) for frame in video]

						return video







def 						__magic_name__(			_A    ,   _A=False    ,   _A=False    ,   _A=False       ):
						'''simple docstring'''





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

						UpperCamelCase__       =			[]
						for i in range(image_processor_tester.batch_size       ):
												if equal_resolution:
																		UpperCamelCase__       =			UpperCamelCase__       =			image_processor_tester.max_resolution
												else:
																		UpperCamelCase__     , UpperCamelCase__       =			np.random.choice(
																		    np.arange(image_processor_tester.min_resolution    ,   image_processor_tester.max_resolution       )    ,   2       )
																		UpperCamelCase__       =			prepare_video(
																		    image_processor_tester=_A    ,   width=_A    ,   height=_A    ,   numpify=_A    ,   torchify=_A    ,   )
												video_inputs.append(_A       )

						return video_inputs
class  _SCREAMING_SNAKE_CASE				(		unittest.TestCase						):


			'''simple docstring'''





			def __init__( self				:    Dict			,   lowercase				:    Optional[Any]			,   lowercase				:    Dict=7			,   lowercase				:    str=3			,   lowercase				:    List[str]=4			,   lowercase				:    Union[str, Any]=1_8			,   lowercase				:    Union[str, Any]=3_0			,   lowercase				:    Union[str, Any]=4_0_0			,   lowercase				:    List[Any]=True			,   lowercase				:    Tuple=None			,   lowercase				:    str=True			,   lowercase				:    List[Any]=[0.5, 0.5, 0.5]			,   lowercase				:    Optional[int]=[0.5, 0.5, 0.5]			,   lowercase				:    List[str]=True			,   lowercase				:    List[str]=None			,   )				->     Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			size if size is not None else {"""shortest_edge""": 1_8}
									UpperCamelCase__       =			crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

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







			def 					A   ( self				:    str      )				->     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,
									    "do_center_crop": self.do_center_crop,
									    "crop_size": self.crop_size,
									}
@require_torch
@require_vision
class  _SCREAMING_SNAKE_CASE				(		SCREAMING_SNAKE_CASE							,unittest.TestCase						):


			'''simple docstring'''





			__a				:				Optional[Any]         =       TvltImageProcessor if is_vision_available() else None






			def 					A   ( self				:    Dict      )				->     Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			TvltImageProcessorTester(self      )






			@property
			def 					A   ( self				:    str      )				->     int:

									'''simple docstring'''







									return self.image_processor_tester.prepare_image_processor_dict()






			def 					A   ( self				:    List[Any]      )				->     Tuple:

									'''simple docstring'''







									UpperCamelCase__       =			self.image_processing_class(**self.image_processor_dict      )
									self.assertTrue(hasattr(lowercase			,   """image_mean"""      )      )
									self.assertTrue(hasattr(lowercase			,   """image_std"""      )      )
									self.assertTrue(hasattr(lowercase			,   """do_normalize"""      )      )
									self.assertTrue(hasattr(lowercase			,   """do_resize"""      )      )
									self.assertTrue(hasattr(lowercase			,   """do_center_crop"""      )      )
									self.assertTrue(hasattr(lowercase			,   """size"""      )      )






			def 					A   ( self				:    Union[str, Any]      )				->     List[Any]:

									'''simple docstring'''







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

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processor(lowercase			,   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 					A   ( self				:    Optional[Any]      )				->     Tuple:

									'''simple docstring'''







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

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processor(lowercase			,   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 					A   ( self				:    str      )				->     str:

									'''simple docstring'''







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

									# Test not batched input
									UpperCamelCase__       =			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
									UpperCamelCase__       =			image_processor(lowercase			,   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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowerCamelCase_					:			str     						=				{'''configuration_hubert''': ['''HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''HubertConfig''']}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCamelCase_					:			Union[str, Any]     						=				[
					    '''HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''HubertForCTC''',
					    '''HubertForSequenceClassification''',
					    '''HubertModel''',
					    '''HubertPreTrainedModel''',
					]


try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowerCamelCase_					:			Optional[Any]     						=				[
					    '''TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TFHubertForCTC''',
					    '''TFHubertModel''',
					    '''TFHubertPreTrainedModel''',
					]

if TYPE_CHECKING:
					from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_hubert import (
										    HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    HubertForCTC,
										    HubertForSequenceClassification,
										    HubertModel,
										    HubertPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_hubert import (
										    TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFHubertForCTC,
										    TFHubertModel,
										    TFHubertPreTrainedModel,
										)


else:
					import sys

					lowerCamelCase_					:			Dict     						=				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
