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


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import MobileViTImageProcessor






class 						A   (   unittest.TestCase   ):





							def __init__(      self				:							int     ,		__a				:							List[str]     ,		__a				:							Optional[int]=7     ,		__a				:							List[str]=3     ,		__a				:							Dict=1_8     ,		__a				:							Optional[int]=3_0     ,		__a				:							Optional[Any]=4_0_0     ,		__a				:							List[str]=True     ,		__a				:							Union[str, Any]=None     ,		__a				:							List[Any]=True     ,		__a				:							Optional[int]=None     ,		__a				:							int=True     ,		)							->	Tuple:
								__UpperCAmelCase							=			size if size is not None else {'''shortest_edge''': 2_0}
								__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							=			image_size
								__UpperCAmelCase							=			min_resolution
								__UpperCAmelCase							=			max_resolution
								__UpperCAmelCase							=			do_resize
								__UpperCAmelCase							=			size
								__UpperCAmelCase							=			do_center_crop
								__UpperCAmelCase							=			crop_size
								__UpperCAmelCase							=			do_flip_channel_order






							def       snake_case__						(      self				:							Union[str, Any]	)							->	Union[str, Any]:
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_center_crop": self.do_center_crop,
								    "crop_size": self.crop_size,
								    "do_flip_channel_order": self.do_flip_channel_order,
								}






@require_torch
@require_vision
class 						A   (   UpperCAmelCase       ,	unittest.TestCase   ):
							a_        =      MobileViTImageProcessor if is_vision_available() else None





							def       snake_case__						(      self				:							List[str]	)							->	int:
								__UpperCAmelCase							=			MobileViTImageProcessingTester(self	)





							@property
							def       snake_case__						(      self				:							Dict	)							->	Dict:
								return self.image_processor_tester.prepare_image_processor_dict()





							def       snake_case__						(      self				:							List[str]	)							->	Tuple:
								__UpperCAmelCase							=			self.image_processing_class(**self.image_processor_dict	)
								self.assertTrue(hasattr(__a     ,		'''do_resize'''	)	)
								self.assertTrue(hasattr(__a     ,		'''size'''	)	)
								self.assertTrue(hasattr(__a     ,		'''do_center_crop'''	)	)
								self.assertTrue(hasattr(__a     ,		'''center_crop'''	)	)
								self.assertTrue(hasattr(__a     ,		'''do_flip_channel_order'''	)	)





							def       snake_case__						(      self				:							Optional[Any]	)							->	Union[str, Any]:
								__UpperCAmelCase							=			self.image_processing_class.from_dict(self.image_processor_dict	)
								self.assertEqual(image_processor.size     ,		{'''shortest_edge''': 2_0}	)
								self.assertEqual(image_processor.crop_size     ,		{'''height''': 1_8, '''width''': 1_8}	)

								__UpperCAmelCase							=			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       snake_case__						(      self				:							Dict	)							->	List[str]:
								pass





							def       snake_case__						(      self				:							List[Any]	)							->	int:
								# Initialize image_processing
								__UpperCAmelCase							=			self.image_processing_class(**self.image_processor_dict	)
								# create random PIL images
								__UpperCAmelCase							=			prepare_image_inputs(self.image_processor_tester     ,		equal_resolution=__a	)
								for image in image_inputs:
									self.assertIsInstance(__a     ,		Image.Image	)

								# Test not batched input
								__UpperCAmelCase							=			image_processing(image_inputs[0]     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )     ,		)

								# Test batched
								__UpperCAmelCase							=			image_processing(__a     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )     ,		)





							def       snake_case__						(      self				:							Optional[int]	)							->	List[str]:
								# Initialize image_processing
								__UpperCAmelCase							=			self.image_processing_class(**self.image_processor_dict	)
								# create random numpy tensors
								__UpperCAmelCase							=			prepare_image_inputs(self.image_processor_tester     ,		equal_resolution=__a     ,		numpify=__a	)
								for image in image_inputs:
									self.assertIsInstance(__a     ,		np.ndarray	)

								# Test not batched input
								__UpperCAmelCase							=			image_processing(image_inputs[0]     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )     ,		)

								# Test batched
								__UpperCAmelCase							=			image_processing(__a     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        self.image_processor_tester.batch_size,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )     ,		)






							def       snake_case__						(      self				:							Tuple	)							->	Union[str, Any]:
								# Initialize image_processing
								__UpperCAmelCase							=			self.image_processing_class(**self.image_processor_dict	)
								# create random PyTorch tensors
								__UpperCAmelCase							=			prepare_image_inputs(self.image_processor_tester     ,		equal_resolution=__a     ,		torchify=__a	)
								for image in image_inputs:
									self.assertIsInstance(__a     ,		torch.Tensor	)

								# Test not batched input
								__UpperCAmelCase							=			image_processing(image_inputs[0]     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        1,
								        self.image_processor_tester.num_channels,
								        self.image_processor_tester.crop_size['''height'''],
								        self.image_processor_tester.crop_size['''width'''],
								    )     ,		)

								# Test batched
								__UpperCAmelCase							=			image_processing(__a     ,		return_tensors='''pt'''	).pixel_values
								self.assertEqual(
								    encoded_images.shape     ,		(
								        self.image_processor_tester.batch_size,
								        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_speech_available, is_torch_available


__lowerCAmelCase	:       List[Any]						       =	{
    "configuration_audio_spectrogram_transformer": [
        "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "ASTConfig",
    ]
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__lowerCAmelCase	:       str						       =	[
					    "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "ASTForAudioClassification",
					    "ASTModel",
					    "ASTPreTrainedModel",
					]

try:
					if not is_speech_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__lowerCAmelCase	:       Union[str, Any]						       =	["ASTFeatureExtractor"]

if TYPE_CHECKING:
					from .configuration_audio_spectrogram_transformer import (
					    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    ASTConfig,
					)

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_audio_spectrogram_transformer import (
										    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
										    ASTForAudioClassification,
										    ASTModel,
										    ASTPreTrainedModel,
										)

					try:
										if not is_speech_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
					import sys

					__lowerCAmelCase	:       Optional[Any]						       =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
