






from typing import Dict, List, Optional, Union

import numpy as np

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,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
 import PIL


lowerCamelCase	:							List[Any]				=logging.get_logger(__name__)





class 			__a  (    _SCREAMING_SNAKE_CASE       ):
 _lowerCAmelCase       :       Dict        = ['''pixel_values''']







 def __init__(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   bool = True							,   SCREAMING_SNAKE_CASE					:   Dict[str, int] = None							,   SCREAMING_SNAKE_CASE					:   float = None							,   SCREAMING_SNAKE_CASE					:   PILImageResampling = PILImageResampling.BILINEAR							,   SCREAMING_SNAKE_CASE					:   bool = True							,   SCREAMING_SNAKE_CASE					:   Union[int, float] = 1 / 2_55							,   SCREAMING_SNAKE_CASE					:   bool = True							,   SCREAMING_SNAKE_CASE					:   Optional[Union[float, List[float]]] = None							,   SCREAMING_SNAKE_CASE					:   Optional[Union[float, List[float]]] = None							,   **SCREAMING_SNAKE_CASE					:   List[str]							,   ):


      '''simple docstring'''






      super().__init__(**_lowerCAmelCase						)
      UpperCamelCase__			:   List[Any]       				=  size if size is not None else {"shortest_edge": 3_84}
      UpperCamelCase__			:   List[Any]       				=  get_size_dict(_lowerCAmelCase							,   default_to_square=_lowerCAmelCase						)

      UpperCamelCase__			:   Dict       				=  do_resize
      UpperCamelCase__			:   Optional[Any]       				=  size
      # Default value set here for backwards compatibility where the value in config is None
      UpperCamelCase__			:   Dict       				=  crop_pct if crop_pct is not None else 2_24 / 2_56
      UpperCamelCase__			:   Union[str, Any]       				=  resample
      UpperCamelCase__			:   int       				=  do_rescale
      UpperCamelCase__			:   Tuple       				=  rescale_factor
      UpperCamelCase__			:   Tuple       				=  do_normalize
      UpperCamelCase__			:   List[Any]       				=  image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      UpperCamelCase__			:   Dict       				=  image_std if image_std is not None else IMAGENET_STANDARD_STD







 def 					__lowercase					(		self					:   List[str]							,   SCREAMING_SNAKE_CASE					:   np.ndarray							,   SCREAMING_SNAKE_CASE					:   Dict[str, int]							,   SCREAMING_SNAKE_CASE					:   float							,   SCREAMING_SNAKE_CASE					:   PILImageResampling = PILImageResampling.BICUBIC							,   SCREAMING_SNAKE_CASE					:   Optional[Union[str, ChannelDimension]] = None							,   **SCREAMING_SNAKE_CASE					:   Optional[Any]							,   ):


      '''simple docstring'''






      UpperCamelCase__			:   int       				=  get_size_dict(_lowerCAmelCase							,   default_to_square=_lowerCAmelCase						)
      if "shortest_edge" not in size:
           raise ValueError(F'Size dictionary must contain \'shortest_edge\' key. Got {size.keys()}'						)
      UpperCamelCase__			:   Optional[int]       				=  size["shortest_edge"]

      if shortest_edge < 3_84:
           # maintain same ratio, resizing shortest edge to shortest_edge/crop_pct
           UpperCamelCase__			:   str       				=  int(shortest_edge / crop_pct						)
           UpperCamelCase__			:   Optional[Any]       				=  get_resize_output_image_size(_lowerCAmelCase							,   size=_lowerCAmelCase							,   default_to_square=_lowerCAmelCase						)
           UpperCamelCase__			:   Optional[Any]       				=  resize(image=_lowerCAmelCase							,   size=_lowerCAmelCase							,   resample=_lowerCAmelCase							,   data_format=_lowerCAmelCase							,   **_lowerCAmelCase						)
           # then crop to (shortest_edge, shortest_edge)
           return center_crop(image=_lowerCAmelCase							,   size=(shortest_edge, shortest_edge)							,   data_format=_lowerCAmelCase							,   **_lowerCAmelCase						)
      else:
           # warping (no cropping) when evaluated at 384 or larger
           return resize(
               _lowerCAmelCase							,   size=(shortest_edge, shortest_edge)							,   resample=_lowerCAmelCase							,   data_format=_lowerCAmelCase							,   **_lowerCAmelCase						)







 def 					__lowercase					(		self					:   Union[str, Any]							,   SCREAMING_SNAKE_CASE					:   np.ndarray							,   SCREAMING_SNAKE_CASE					:   Union[int, float]							,   SCREAMING_SNAKE_CASE					:   Optional[Union[str, ChannelDimension]] = None							,   **SCREAMING_SNAKE_CASE					:   Any							,   ):


      '''simple docstring'''






      return rescale(_lowerCAmelCase							,   scale=_lowerCAmelCase							,   data_format=_lowerCAmelCase							,   **_lowerCAmelCase						)







 def 					__lowercase					(		self					:   Any							,   SCREAMING_SNAKE_CASE					:   np.ndarray							,   SCREAMING_SNAKE_CASE					:   Union[float, List[float]]							,   SCREAMING_SNAKE_CASE					:   Union[float, List[float]]							,   SCREAMING_SNAKE_CASE					:   Optional[Union[str, ChannelDimension]] = None							,   **SCREAMING_SNAKE_CASE					:   Tuple							,   ):


      '''simple docstring'''






      return normalize(_lowerCAmelCase							,   mean=_lowerCAmelCase							,   std=_lowerCAmelCase							,   data_format=_lowerCAmelCase							,   **_lowerCAmelCase						)







 def 					__lowercase					(		self					:   int							,   SCREAMING_SNAKE_CASE					:   ImageInput							,   SCREAMING_SNAKE_CASE					:   bool = None							,   SCREAMING_SNAKE_CASE					:   Dict[str, int] = None							,   SCREAMING_SNAKE_CASE					:   float = None							,   SCREAMING_SNAKE_CASE					:   PILImageResampling = None							,   SCREAMING_SNAKE_CASE					:   bool = None							,   SCREAMING_SNAKE_CASE					:   float = None							,   SCREAMING_SNAKE_CASE					:   bool = None							,   SCREAMING_SNAKE_CASE					:   Optional[Union[float, List[float]]] = None							,   SCREAMING_SNAKE_CASE					:   Optional[Union[float, List[float]]] = None							,   SCREAMING_SNAKE_CASE					:   Optional[Union[str, TensorType]] = None							,   SCREAMING_SNAKE_CASE					:   ChannelDimension = ChannelDimension.FIRST							,   **SCREAMING_SNAKE_CASE					:   List[str]							,   ):


      '''simple docstring'''






      UpperCamelCase__			:   Any       				=  do_resize if do_resize is not None else self.do_resize
      UpperCamelCase__			:   Tuple       				=  crop_pct if crop_pct is not None else self.crop_pct
      UpperCamelCase__			:   Dict       				=  resample if resample is not None else self.resample
      UpperCamelCase__			:   Optional[int]       				=  do_rescale if do_rescale is not None else self.do_rescale
      UpperCamelCase__			:   Tuple       				=  rescale_factor if rescale_factor is not None else self.rescale_factor
      UpperCamelCase__			:   List[str]       				=  do_normalize if do_normalize is not None else self.do_normalize
      UpperCamelCase__			:   List[Any]       				=  image_mean if image_mean is not None else self.image_mean
      UpperCamelCase__			:   Optional[Any]       				=  image_std if image_std is not None else self.image_std

      UpperCamelCase__			:   int       				=  size if size is not None else self.size
      UpperCamelCase__			:   Union[str, Any]       				=  get_size_dict(_lowerCAmelCase							,   default_to_square=_lowerCAmelCase						)

      UpperCamelCase__			:   List[Any]       				=  make_list_of_images(_lowerCAmelCase						)

      if not valid_images(_lowerCAmelCase						):
           raise ValueError(
               "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
               "torch.Tensor, tf.Tensor or jax.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_resize and size["shortest_edge"] < 3_84 and crop_pct is None:
           raise ValueError("crop_pct must be specified if size < 384."						)

      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."						)

      # All transformations expect numpy arrays.
      UpperCamelCase__			:   int       				=  [to_numpy_array(_lowerCAmelCase						) for image in images]

      if do_resize:
           UpperCamelCase__			:   Any       				=  [self.resize(image=_lowerCAmelCase							,   size=_lowerCAmelCase							,   crop_pct=_lowerCAmelCase							,   resample=_lowerCAmelCase						) for image in images]

      if do_rescale:
           UpperCamelCase__			:   Dict       				=  [self.rescale(image=_lowerCAmelCase							,   scale=_lowerCAmelCase						) for image in images]

      if do_normalize:
           UpperCamelCase__			:   List[str]       				=  [self.normalize(image=_lowerCAmelCase							,   mean=_lowerCAmelCase							,   std=_lowerCAmelCase						) for image in images]

      UpperCamelCase__			:   Tuple       				=  [to_channel_dimension_format(_lowerCAmelCase							,   _lowerCAmelCase						) for image in images]

      UpperCamelCase__			:   Optional[Any]       				=  {"pixel_values": images}
      return BatchFeature(data=_lowerCAmelCase							,   tensor_type=_lowerCAmelCase						)





from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase__ :   List[str]					=							logging.get_logger(__name__)

lowerCamelCase__ :   List[str]					=							{
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE					):


 '''simple docstring'''







 lowercase_				    =    "speech_to_text"
 lowercase_				    =    ["past_key_values"]
 lowercase_				    =    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}



 def __init__(							self  :		Tuple				,				_lowerCAmelCase  :		List[Any]=10_000				,				_lowerCAmelCase  :		List[Any]=12				,				_lowerCAmelCase  :		Union[str, Any]=2_048				,				_lowerCAmelCase  :		Optional[int]=4				,				_lowerCAmelCase  :		Union[str, Any]=6				,				_lowerCAmelCase  :		Optional[int]=2_048				,				_lowerCAmelCase  :		Optional[Any]=4				,				_lowerCAmelCase  :		Any=0.0				,				_lowerCAmelCase  :		Optional[Any]=0.0				,				_lowerCAmelCase  :		List[str]=True				,				_lowerCAmelCase  :		List[Any]=True				,				_lowerCAmelCase  :		int="relu"				,				_lowerCAmelCase  :		Union[str, Any]=256				,				_lowerCAmelCase  :		List[str]=0.1				,				_lowerCAmelCase  :		str=0.0				,				_lowerCAmelCase  :		Tuple=0.0				,				_lowerCAmelCase  :		List[str]=0.02				,				_lowerCAmelCase  :		List[str]=2				,				_lowerCAmelCase  :		Tuple=True				,				_lowerCAmelCase  :		List[str]=1				,				_lowerCAmelCase  :		str=0				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Union[str, Any]=6_000				,				_lowerCAmelCase  :		List[str]=1_024				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Optional[Any]=(5, 5)				,				_lowerCAmelCase  :		str=1_024				,				_lowerCAmelCase  :		str=80				,				_lowerCAmelCase  :		Tuple=1				,				**_lowerCAmelCase  :		Any				,				):
       SCREAMING_SNAKE_CASE_							=			vocab_size
       SCREAMING_SNAKE_CASE_							=			d_model
       SCREAMING_SNAKE_CASE_							=			encoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			encoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			decoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			decoder_layers
       SCREAMING_SNAKE_CASE_							=			decoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			dropout
       SCREAMING_SNAKE_CASE_							=			attention_dropout
       SCREAMING_SNAKE_CASE_							=			activation_dropout
       SCREAMING_SNAKE_CASE_							=			activation_function
       SCREAMING_SNAKE_CASE_							=			init_std
       SCREAMING_SNAKE_CASE_							=			encoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			decoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			use_cache
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			scale_embedding  # scale factor will be sqrt(d_model) if True
       SCREAMING_SNAKE_CASE_							=			max_source_positions
       SCREAMING_SNAKE_CASE_							=			max_target_positions
       SCREAMING_SNAKE_CASE_							=			num_conv_layers
       SCREAMING_SNAKE_CASE_							=			list(_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			conv_channels
       SCREAMING_SNAKE_CASE_							=			input_feat_per_channel
       SCREAMING_SNAKE_CASE_							=			input_channels

       if len(self.conv_kernel_sizes						) != self.num_conv_layers:
             raise ValueError(
                 'Configuration for convolutional module is incorrect. '
                 'It is required that `len(config.conv_kernel_sizes)` == `config.num_conv_layers` '
                 F"but is `len(config.conv_kernel_sizes) = {len(self.conv_kernel_sizes						)}`, "
                 F"`config.num_conv_layers = {self.num_conv_layers}`."						)

       super().__init__(
           pad_token_id=_lowerCAmelCase				,				bos_token_id=_lowerCAmelCase				,				eos_token_id=_lowerCAmelCase				,				is_encoder_decoder=_lowerCAmelCase				,				decoder_start_token_id=_lowerCAmelCase				,				**_lowerCAmelCase				,				)