
"""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 VideoMAEImageProcessor




class  _snake_case	(    unittest.TestCase							):






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






												"""simple docstring"""



												__a:    str		     =       size if size is not None else {"""shortest_edge""": 1_8}
												__a:    List[str]		     =       crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}

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






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






@require_torch
@require_vision
class  _snake_case	(    _a			,					unittest.TestCase							):
							SCREAMING_SNAKE_CASE		  =    VideoMAEImageProcessor if is_vision_available() else None






							def 				__lowercase	(       self    :      List[str]     ):






												"""simple docstring"""



												__a:    Optional[Any]		     =       VideoMAEImageProcessingTester(self     )






							@property
							def 				__lowercase	(       self    :      int     ):






												"""simple docstring"""



												return self.image_processor_tester.prepare_image_processor_dict()






							def 				__lowercase	(       self    :      str     ):






												"""simple docstring"""



												__a:    Union[str, Any]		     =       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 				__lowercase	(       self    :      Optional[int]     ):






												"""simple docstring"""



												__a:    Union[str, Any]		     =       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}     )

												__a:    List[str]		     =       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 				__lowercase	(       self    :      Optional[Any]     ):






												"""simple docstring"""



												pass






							def 				__lowercase	(       self    :      int     ):






												"""simple docstring"""



												__a:    Union[str, Any]		     =       self.image_processing_class(**self.image_processor_dict     )
												# create random PIL videos
												__a:    int		     =       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
												__a:    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
												__a:    Optional[Any]		     =       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 				__lowercase	(       self    :      Optional[Any]     ):






												"""simple docstring"""



												__a:    int		     =       self.image_processing_class(**self.image_processor_dict     )
												# create random numpy tensors
												__a:    str		     =       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
												__a:    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
												__a:    List[Any]		     =       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 				__lowercase	(       self    :      Any     ):






												"""simple docstring"""



												__a:    Dict		     =       self.image_processing_class(**self.image_processor_dict     )
												# create random PyTorch tensors
												__a:    str		     =       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
												__a:    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
												__a:    Optional[Any]		     =       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"""],
												    )    ,			)








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


UpperCAmelCase_					:		int           = {
    '''configuration_unispeech_sat''': ['''UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''UniSpeechSatConfig'''],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase_					:		Tuple           = [
	    '''UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''UniSpeechSatForAudioFrameClassification''',
	    '''UniSpeechSatForCTC''',
	    '''UniSpeechSatForPreTraining''',
	    '''UniSpeechSatForSequenceClassification''',
	    '''UniSpeechSatForXVector''',
	    '''UniSpeechSatModel''',
	    '''UniSpeechSatPreTrainedModel''',
	]

if TYPE_CHECKING:
	from .configuration_unispeech_sat import UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP, UniSpeechSatConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_unispeech_sat import (
		    UNISPEECH_SAT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    UniSpeechSatForAudioFrameClassification,
		    UniSpeechSatForCTC,
		    UniSpeechSatForPreTraining,
		    UniSpeechSatForSequenceClassification,
		    UniSpeechSatForXVector,
		    UniSpeechSatModel,
		    UniSpeechSatPreTrainedModel,
		)

else:
	import sys

	UpperCAmelCase_					:		str           = _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
