



"""simple docstring"""







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 convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_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


UpperCamelCase     =							logging.get_logger(__name__)






class       UpperCamelCase__			(   _lowerCAmelCase      ):

			"""simple docstring"""


			A__	:					Dict							  =     ["pixel_values"]


			def __init__(      self						,	SCREAMING_SNAKE_CASE__ = True						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = PILImageResampling.BICUBIC						,	SCREAMING_SNAKE_CASE__ = True						,	SCREAMING_SNAKE_CASE__ = 1 / 255						,	SCREAMING_SNAKE_CASE__ = True						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = True						,	**SCREAMING_SNAKE_CASE__						,	)      ->	None:
				super().__init__(**SCREAMING_SNAKE_CASE__		)
				A__											=					size if size is not None else {"height": 384, "width": 384}
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__						,	default_to_square=SCREAMING_SNAKE_CASE__		)

				A__											=					do_resize
				A__											=					size
				A__											=					resample
				A__											=					do_rescale
				A__											=					rescale_factor
				A__											=					do_normalize
				A__											=					image_mean if image_mean is not None else OPENAI_CLIP_MEAN
				A__											=					image_std if image_std is not None else OPENAI_CLIP_STD
				A__											=					do_convert_rgb


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = PILImageResampling.BICUBIC						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	np.ndarray:
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__						,	default_to_square=SCREAMING_SNAKE_CASE__		)
				if "height" not in size or "width" not in size:
					raise ValueError(f"""The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}"""		)
				A__											=					(size["height"], size["width"])
				return resize(SCREAMING_SNAKE_CASE__						,	size=SCREAMING_SNAKE_CASE__						,	resample=SCREAMING_SNAKE_CASE__						,	data_format=SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__		)


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	str:
				return rescale(SCREAMING_SNAKE_CASE__						,	scale=SCREAMING_SNAKE_CASE__						,	data_format=SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__		)


			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None						,	**SCREAMING_SNAKE_CASE__						,	)      ->	np.ndarray:
				return normalize(SCREAMING_SNAKE_CASE__						,	mean=SCREAMING_SNAKE_CASE__						,	std=SCREAMING_SNAKE_CASE__						,	data_format=SCREAMING_SNAKE_CASE__						,	**SCREAMING_SNAKE_CASE__		)







			def   snake_case__	(      self						,	SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = None						,	SCREAMING_SNAKE_CASE__ = ChannelDimension.FIRST						,	**SCREAMING_SNAKE_CASE__						,	)      ->	PIL.Image.Image:
				A__											=					do_resize if do_resize is not None else self.do_resize
				A__											=					resample if resample is not None else self.resample
				A__											=					do_rescale if do_rescale is not None else self.do_rescale
				A__											=					rescale_factor if rescale_factor is not None else self.rescale_factor
				A__											=					do_normalize if do_normalize is not None else self.do_normalize
				A__											=					image_mean if image_mean is not None else self.image_mean
				A__											=					image_std if image_std is not None else self.image_std
				A__											=					do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

				A__											=					size if size is not None else self.size
				A__											=					get_size_dict(SCREAMING_SNAKE_CASE__						,	default_to_square=SCREAMING_SNAKE_CASE__		)

				A__											=					make_list_of_images(SCREAMING_SNAKE_CASE__		)

				if not valid_images(SCREAMING_SNAKE_CASE__		):
					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_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."		)

				# PIL RGBA images are converted to RGB
				if do_convert_rgb:
					A__											=					[convert_to_rgb(SCREAMING_SNAKE_CASE__		) for image in images]

				# All transformations expect numpy arrays.
				A__											=					[to_numpy_array(SCREAMING_SNAKE_CASE__		) for image in images]

				if do_resize:
					A__											=					[self.resize(image=SCREAMING_SNAKE_CASE__						,	size=SCREAMING_SNAKE_CASE__						,	resample=SCREAMING_SNAKE_CASE__		) for image in images]

				if do_rescale:
					A__											=					[self.rescale(image=SCREAMING_SNAKE_CASE__						,	scale=SCREAMING_SNAKE_CASE__		) for image in images]

				if do_normalize:
					A__											=					[self.normalize(image=SCREAMING_SNAKE_CASE__						,	mean=SCREAMING_SNAKE_CASE__						,	std=SCREAMING_SNAKE_CASE__		) for image in images]

				A__											=					[to_channel_dimension_format(SCREAMING_SNAKE_CASE__						,	SCREAMING_SNAKE_CASE__		) for image in images]

				A__											=					BatchFeature(data={"pixel_values": images}						,	tensor_type=SCREAMING_SNAKE_CASE__		)

				return encoded_outputs











"""simple docstring"""



import functools
import operator

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


a_					=     logging.get_logger(__name__)

a_					=     {
    """microsoft/unispeech-large-1500h-cv""": (
        """https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"""
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""unispeech"""

 def __init__(       self   ,		__lowerCamelCase=32   ,		__lowerCamelCase=768   ,		__lowerCamelCase=12   ,		__lowerCamelCase=12   ,		__lowerCamelCase=3072   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=1e-5   ,		__lowerCamelCase="group"   ,		__lowerCamelCase="gelu"   ,		__lowerCamelCase=(512, 512, 512, 512, 512, 512, 512)   ,		__lowerCamelCase=(5, 2, 2, 2, 2, 2, 2)   ,		__lowerCamelCase=(10, 3, 3, 3, 3, 2, 2)   ,		__lowerCamelCase=False   ,		__lowerCamelCase=128   ,		__lowerCamelCase=16   ,		__lowerCamelCase=False   ,		__lowerCamelCase=True   ,		__lowerCamelCase=0.0_5   ,		__lowerCamelCase=10   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=10   ,		__lowerCamelCase=0   ,		__lowerCamelCase=320   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase=100   ,		__lowerCamelCase=256   ,		__lowerCamelCase=256   ,		__lowerCamelCase=0.1   ,		__lowerCamelCase="mean"   ,		__lowerCamelCase=False   ,		__lowerCamelCase=False   ,		__lowerCamelCase=256   ,		__lowerCamelCase=80   ,		__lowerCamelCase=0   ,		__lowerCamelCase=1   ,		__lowerCamelCase=2   ,		__lowerCamelCase=0.5   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase   ,		pad_token_id=__lowerCamelCase   ,		bos_token_id=__lowerCamelCase   ,		eos_token_id=__lowerCamelCase    )
     __A       :		Dict							=	hidden_size
     __A       :		Dict							=	feat_extract_norm
     __A       :		int							=	feat_extract_activation
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	list(__lowerCamelCase    )
     __A       :		Dict							=	list(__lowerCamelCase    )
     __A       :		str							=	conv_bias
     __A       :		Optional[int]							=	num_conv_pos_embeddings
     __A       :		int							=	num_conv_pos_embedding_groups
     __A       :		Union[str, Any]							=	len(self.conv_dim    )
     __A       :		List[str]							=	num_hidden_layers
     __A       :		Dict							=	intermediate_size
     __A       :		List[str]							=	hidden_act
     __A       :		int							=	num_attention_heads
     __A       :		str							=	hidden_dropout
     __A       :		str							=	attention_dropout
     __A       :		Optional[Any]							=	activation_dropout
     __A       :		Optional[int]							=	feat_proj_dropout
     __A       :		Optional[Any]							=	final_dropout
     __A       :		List[Any]							=	layerdrop
     __A       :		Any							=	layer_norm_eps
     __A       :		str							=	initializer_range
     __A       :		List[str]							=	num_ctc_classes
     __A       :		Dict							=	vocab_size
     __A       :		Dict							=	do_stable_layer_norm
     __A       :		Union[str, Any]							=	use_weighted_layer_sum
     __A       :		Tuple							=	classifier_proj_size

     if (
         (len(self.conv_stride    ) != self.num_feat_extract_layers)
         or (len(self.conv_kernel    ) != self.num_feat_extract_layers)
         or (len(self.conv_dim    ) != self.num_feat_extract_layers)
     ):
         raise ValueError(
             '''Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='''
             ''' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='''
             F""" {len(self.conv_dim    )}`, `len(config.conv_stride) = {len(self.conv_stride    )}`,"""
             F""" `len(config.conv_kernel) = {len(self.conv_kernel    )}`."""    )

     # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
     __A       :		List[Any]							=	apply_spec_augment
     __A       :		str							=	mask_time_prob
     __A       :		Dict							=	mask_time_length
     __A       :		List[str]							=	mask_time_min_masks
     __A       :		Union[str, Any]							=	mask_feature_prob
     __A       :		Tuple							=	mask_feature_length
     __A       :		Any							=	mask_feature_min_masks

     # parameters for pretraining with codevector quantized representations
     __A       :		int							=	num_codevectors_per_group
     __A       :		Any							=	num_codevector_groups
     __A       :		Optional[Any]							=	contrastive_logits_temperature
     __A       :		Dict							=	feat_quantizer_dropout
     __A       :		Tuple							=	num_negatives
     __A       :		List[str]							=	codevector_dim
     __A       :		str							=	proj_codevector_dim
     __A       :		Union[str, Any]							=	diversity_loss_weight

     # ctc loss
     __A       :		Tuple							=	ctc_loss_reduction
     __A       :		Optional[int]							=	ctc_zero_infinity

     # pretraining loss
     __A       :		str							=	replace_prob







 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return functools.reduce(operator.mul   ,		self.conv_stride   ,		1    )




