






'''simple docstring'''





from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
						import PIL

_UpperCamelCase						:						List[str]  =					logging.get_logger(__name__)
def __UpperCAmelCase   (					A					:			Optional[Any]		)    ->   List[List[ImageInput]]:
			if isinstance(A			,       (list, tuple)		) and isinstance(videos[0]			,       (list, tuple)		) and is_valid_image(videos[0][0]		):
						return videos

			elif isinstance(A			,       (list, tuple)		) and is_valid_image(videos[0]		):
						return [videos]

			elif is_valid_image(A		):
						return [[videos]]

			raise ValueError(F"Could not make batched video from {videos}"		)







class  snake_case__      (					UpperCamelCase):
					a_        =					["pixel_values"]




					def __init__(  self  :		Union[str, Any]				, _A  :		bool = True				, _A  :		Dict[str, int] = None				, _A  :		PILImageResampling = PILImageResampling.BILINEAR				, _A  :		bool = True				, _A  :		Dict[str, int] = None				, _A  :		bool = True				, _A  :		Union[int, float] = 1 / 2_55				, _A  :		bool = True				, _A  :		bool = True				, _A  :		Optional[Union[float, List[float]]] = None				, _A  :		Optional[Union[float, List[float]]] = None				, **_A  :		Dict				, )    ->							None:
								super().__init__(**_A      )
								UpperCAmelCase_      :       Dict          =       size if size is not None else {'''shortest_edge''': 2_56}
								UpperCAmelCase_      :       Dict          =       get_size_dict(_A				, default_to_square=_A      )
								UpperCAmelCase_      :       List[Any]          =       crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
								UpperCAmelCase_      :       Dict          =       get_size_dict(_A				, param_name='''crop_size'''      )

								UpperCAmelCase_      :       Union[str, Any]          =       do_resize
								UpperCAmelCase_      :       Union[str, Any]          =       size
								UpperCAmelCase_      :       Optional[Any]          =       do_center_crop
								UpperCAmelCase_      :       Dict          =       crop_size
								UpperCAmelCase_      :       Any          =       resample
								UpperCAmelCase_      :       Optional[int]          =       do_rescale
								UpperCAmelCase_      :       Dict          =       rescale_factor
								UpperCAmelCase_      :       Tuple          =       offset
								UpperCAmelCase_      :       Dict          =       do_normalize
								UpperCAmelCase_      :       int          =       image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
								UpperCAmelCase_      :       List[str]          =       image_std if image_std is not None else IMAGENET_STANDARD_STD




					def 		A      (  self  :		int				, _A  :		np.ndarray				, _A  :		Dict[str, int]				, _A  :		PILImageResampling = PILImageResampling.BILINEAR				, _A  :		Optional[Union[str, ChannelDimension]] = None				, **_A  :		Optional[Any]				, )    ->							np.ndarray:
								UpperCAmelCase_      :       Dict          =       get_size_dict(_A				, default_to_square=_A      )
								if "shortest_edge" in size:
											UpperCAmelCase_      :       List[Any]          =       get_resize_output_image_size(_A				, size['''shortest_edge''']				, default_to_square=_A      )
								elif "height" in size and "width" in size:
											UpperCAmelCase_      :       str          =       (size['''height'''], size['''width'''])
								else:
											raise ValueError(F"Size must have 'height' and 'width' or 'shortest_edge' as keys. Got {size.keys()}"      )
								return resize(_A				, size=_A				, resample=_A				, data_format=_A				, **_A      )




					def 		A      (  self  :		Dict				, _A  :		np.ndarray				, _A  :		Dict[str, int]				, _A  :		Optional[Union[str, ChannelDimension]] = None				, **_A  :		List[str]				, )    ->							np.ndarray:
								UpperCAmelCase_      :       int          =       get_size_dict(_A      )
								if "height" not in size or "width" not in size:
											raise ValueError(F"Size must have 'height' and 'width' as keys. Got {size.keys()}"      )
								return center_crop(_A				, size=(size['''height'''], size['''width'''])				, data_format=_A				, **_A      )




					def 		A      (  self  :		Any				, _A  :		np.ndarray				, _A  :		Union[int, float]				, _A  :		bool = True				, _A  :		Optional[Union[str, ChannelDimension]] = None				, **_A  :		int				, )    ->							Tuple:
								UpperCAmelCase_      :       str          =       image.astype(np.floataa      )
								if offset:
											UpperCAmelCase_      :       Optional[int]          =       image - (scale / 2)
								return rescale(_A				, scale=_A				, data_format=_A				, **_A      )




					def 		A      (  self  :		Union[str, Any]				, _A  :		np.ndarray				, _A  :		Union[float, List[float]]				, _A  :		Union[float, List[float]]				, _A  :		Optional[Union[str, ChannelDimension]] = None				, **_A  :		Union[str, Any]				, )    ->							np.ndarray:
								return normalize(_A				, mean=_A				, std=_A				, data_format=_A				, **_A      )




					def 		A      (  self  :		Dict				, _A  :		ImageInput				, _A  :		bool = None				, _A  :		Dict[str, int] = None				, _A  :		PILImageResampling = None				, _A  :		bool = None				, _A  :		Dict[str, int] = None				, _A  :		bool = None				, _A  :		float = None				, _A  :		bool = None				, _A  :		bool = None				, _A  :		Optional[Union[float, List[float]]] = None				, _A  :		Optional[Union[float, List[float]]] = None				, _A  :		Optional[ChannelDimension] = ChannelDimension.FIRST				, )    ->							np.ndarray:
								if do_resize and size is None or resample is None:
											raise ValueError('''Size and resample must be specified if do_resize is True.'''      )

								if do_center_crop and crop_size is None:
											raise ValueError('''Crop size must be specified if do_center_crop is True.'''      )

								if do_rescale and rescale_factor is None:
											raise ValueError('''Rescale factor must be specified if do_rescale is True.'''      )

								if do_normalize and (image_mean is None or image_std is None):
											raise ValueError('''Image mean and std must be specified if do_normalize is True.'''      )

								if offset and not do_rescale:
											raise ValueError('''For offset, do_rescale must also be set to True.'''      )

								# All transformations expect numpy arrays.
								UpperCAmelCase_      :       List[Any]          =       to_numpy_array(_A      )

								if do_resize:
											UpperCAmelCase_      :       Optional[Any]          =       self.resize(image=_A				, size=_A				, resample=_A      )

								if do_center_crop:
											UpperCAmelCase_      :       int          =       self.center_crop(_A				, size=_A      )

								if do_rescale:
											UpperCAmelCase_      :       Any          =       self.rescale(image=_A				, scale=_A				, offset=_A      )

								if do_normalize:
											UpperCAmelCase_      :       Dict          =       self.normalize(image=_A				, mean=_A				, std=_A      )

								UpperCAmelCase_      :       Optional[Any]          =       to_channel_dimension_format(_A				, _A      )
								return image





					def 		A      (  self  :		str				, _A  :		ImageInput				, _A  :		bool = None				, _A  :		Dict[str, int] = None				, _A  :		PILImageResampling = None				, _A  :		bool = None				, _A  :		Dict[str, int] = None				, _A  :		bool = None				, _A  :		float = None				, _A  :		bool = None				, _A  :		bool = None				, _A  :		Optional[Union[float, List[float]]] = None				, _A  :		Optional[Union[float, List[float]]] = None				, _A  :		Optional[Union[str, TensorType]] = None				, _A  :		ChannelDimension = ChannelDimension.FIRST				, **_A  :		List[Any]				, )    ->							PIL.Image.Image:
								UpperCAmelCase_      :       List[Any]          =       do_resize if do_resize is not None else self.do_resize
								UpperCAmelCase_      :       List[Any]          =       resample if resample is not None else self.resample
								UpperCAmelCase_      :       Optional[int]          =       do_center_crop if do_center_crop is not None else self.do_center_crop
								UpperCAmelCase_      :       Dict          =       do_rescale if do_rescale is not None else self.do_rescale
								UpperCAmelCase_      :       Optional[Any]          =       rescale_factor if rescale_factor is not None else self.rescale_factor
								UpperCAmelCase_      :       Union[str, Any]          =       offset if offset is not None else self.offset
								UpperCAmelCase_      :       int          =       do_normalize if do_normalize is not None else self.do_normalize
								UpperCAmelCase_      :       Optional[int]          =       image_mean if image_mean is not None else self.image_mean
								UpperCAmelCase_      :       Tuple          =       image_std if image_std is not None else self.image_std

								UpperCAmelCase_      :       Dict          =       size if size is not None else self.size
								UpperCAmelCase_      :       List[Any]          =       get_size_dict(_A				, default_to_square=_A      )
								UpperCAmelCase_      :       List[Any]          =       crop_size if crop_size is not None else self.crop_size
								UpperCAmelCase_      :       Optional[Any]          =       get_size_dict(_A				, param_name='''crop_size'''      )

								if not valid_images(_A      ):
											raise ValueError(
											    '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
											    '''torch.Tensor, tf.Tensor or jax.ndarray.'''      )

								UpperCAmelCase_      :       Dict          =       make_batched(_A      )

								UpperCAmelCase_      :       int          =       [
								    [
								        self._preprocess_image(
								            image=_A				, do_resize=_A				, size=_A				, resample=_A				, do_center_crop=_A				, crop_size=_A				, do_rescale=_A				, rescale_factor=_A				, offset=_A				, do_normalize=_A				, image_mean=_A				, image_std=_A				, data_format=_A				, )
								        for img in video
								    ]
								    for video in videos
								]

								UpperCAmelCase_      :       Optional[int]          =       {'''pixel_values''': videos}
								return BatchFeature(data=_A				, tensor_type=_A      )










'''simple docstring'''





from typing import TYPE_CHECKING

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


_UpperCamelCase						:						Tuple  =					{
    'configuration_audio_spectrogram_transformer': [
        'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ASTConfig',
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_UpperCamelCase						:						Optional[int]  =					[
						    'AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'ASTForAudioClassification',
						    'ASTModel',
						    'ASTPreTrainedModel',
						]

try:
						if not is_speech_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_UpperCamelCase						:						int  =					['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

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


