






import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse('''9.1.0'''):
 lowerCamelCase	:							Any				={
     '''linear''': PIL.Image.Resampling.BILINEAR,
     '''bilinear''': PIL.Image.Resampling.BILINEAR,
     '''bicubic''': PIL.Image.Resampling.BICUBIC,
     '''lanczos''': PIL.Image.Resampling.LANCZOS,
     '''nearest''': PIL.Image.Resampling.NEAREST,
 }
else:
 lowerCamelCase	:							str				={
     '''linear''': PIL.Image.LINEAR,
     '''bilinear''': PIL.Image.BILINEAR,
     '''bicubic''': PIL.Image.BICUBIC,
     '''lanczos''': PIL.Image.LANCZOS,
     '''nearest''': PIL.Image.NEAREST,
 }







def 		SCREAMING_SNAKE_CASE							(					__lowerCAmelCase			) ->	int:
     UpperCamelCase__			:   str       				=  (images / 2 + 0.5).clamp(0					,    1			)
     UpperCamelCase__			:   Dict       				=  images.cpu().permute(0					,    2					,    3					,    1			).float().numpy()
     UpperCamelCase__			:   Union[str, Any]       				=  numpy_to_pil(__lowerCAmelCase			)
     return images







def 		SCREAMING_SNAKE_CASE							(					__lowerCAmelCase			) ->	Tuple:
     if images.ndim == 3:
          UpperCamelCase__			:   Tuple       				=  images[None, ...]
     UpperCamelCase__			:   List[str]       				=  (images * 255).round().astype("uint8"			)
     if images.shape[-1] == 1:
          # special case for grayscale (single channel) images
          UpperCamelCase__			:   Tuple       				=  [Image.fromarray(image.squeeze()					,    mode="L"			) for image in images]
     else:
          UpperCamelCase__			:   List[str]       				=  [Image.fromarray(__lowerCAmelCase			) for image in images]

     return pil_images







from typing import TYPE_CHECKING

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


lowerCamelCase	:							int				={
    '''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	:							Union[str, Any]				=[
     '''AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''ASTForAudioClassification''',
     '''ASTModel''',
     '''ASTPreTrainedModel''',
 ]

try:
 if not is_speech_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowerCamelCase	:							Optional[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

 lowerCamelCase	:							Optional[int]				=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)