



import warnings
from typing import List

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import is_flax_available, is_tf_available, is_torch_available


class   lowercase      (       a       ):
							lowercase__  :    List[str]									=							["""image_processor""", """tokenizer"""]
							lowercase__  :    Any									=							"""OwlViTImageProcessor"""
							lowercase__  :    List[str]									=							("""CLIPTokenizer""", """CLIPTokenizerFast""")




							def __init__(  self				:   List[str]		,							_UpperCamelCase				:   List[str]=None		,							_UpperCamelCase				:   int=None		,							**_UpperCamelCase				:   Tuple )   ->			str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE           =    None
												if "feature_extractor" in kwargs:
																	warnings.warn(
																	    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
																	    " instead."		,							lowercase_		,							)
																	SCREAMING_SNAKE_CASE           =    kwargs.pop("feature_extractor" )

												SCREAMING_SNAKE_CASE           =    image_processor if image_processor is not None else feature_extractor
												if image_processor is None:
																	raise ValueError("You need to specify an `image_processor`." )
												if tokenizer is None:
																	raise ValueError("You need to specify a `tokenizer`." )

												super().__init__(lowercase_		,							lowercase_ )




							def __call__(  self				:   Union[str, Any]		,							_UpperCamelCase				:   Dict=None		,							_UpperCamelCase				:   Tuple=None		,							_UpperCamelCase				:   str=None		,							_UpperCamelCase				:   Optional[int]="max_length"		,							_UpperCamelCase				:   Union[str, Any]="np"		,							**_UpperCamelCase				:   List[Any] )   ->			Optional[Any]:



												'''simple docstring'''

												if text is None and query_images is None and images is None:
																	raise ValueError(
																	    "You have to specify at least one text or query image or image. All three cannot be none." )

												if text is not None:
																	if isinstance(lowercase_		,							lowercase_ ) or (isinstance(lowercase_		,							lowercase_ ) and not isinstance(text[0]		,							lowercase_ )):
																						SCREAMING_SNAKE_CASE           =    [self.tokenizer(lowercase_		,							padding=lowercase_		,							return_tensors=lowercase_		,							**lowercase_ )]

																	elif isinstance(lowercase_		,							lowercase_ ) and isinstance(text[0]		,							lowercase_ ):
																						SCREAMING_SNAKE_CASE           =    []

																						# Maximum number of queries across batch
																						SCREAMING_SNAKE_CASE           =    max([len(lowercase_ ) for t in text] )

																						# Pad all batch samples to max number of text queries
																						for t in text:
																											if len(lowercase_ ) != max_num_queries:
																																SCREAMING_SNAKE_CASE           =    t + [" "] * (max_num_queries - len(lowercase_ ))

																											SCREAMING_SNAKE_CASE           =    self.tokenizer(lowercase_		,							padding=lowercase_		,							return_tensors=lowercase_		,							**lowercase_ )
																											encodings.append(lowercase_ )
																	else:
																						raise TypeError("Input text should be a string, a list of strings or a nested list of strings" )

																	if return_tensors == "np":
																						SCREAMING_SNAKE_CASE           =    np.concatenate([encoding["input_ids"] for encoding in encodings]		,							axis=0 )
																						SCREAMING_SNAKE_CASE           =    np.concatenate([encoding["attention_mask"] for encoding in encodings]		,							axis=0 )

																	elif return_tensors == "jax" and is_flax_available():
																						import jax.numpy as jnp

																						SCREAMING_SNAKE_CASE           =    jnp.concatenate([encoding["input_ids"] for encoding in encodings]		,							axis=0 )
																						SCREAMING_SNAKE_CASE           =    jnp.concatenate([encoding["attention_mask"] for encoding in encodings]		,							axis=0 )

																	elif return_tensors == "pt" and is_torch_available():
																						import torch

																						SCREAMING_SNAKE_CASE           =    torch.cat([encoding["input_ids"] for encoding in encodings]		,							dim=0 )
																						SCREAMING_SNAKE_CASE           =    torch.cat([encoding["attention_mask"] for encoding in encodings]		,							dim=0 )

																	elif return_tensors == "tf" and is_tf_available():
																						import tensorflow as tf

																						SCREAMING_SNAKE_CASE           =    tf.stack([encoding["input_ids"] for encoding in encodings]		,							axis=0 )
																						SCREAMING_SNAKE_CASE           =    tf.stack([encoding["attention_mask"] for encoding in encodings]		,							axis=0 )

																	else:
																						raise ValueError("Target return tensor type could not be returned" )

																	SCREAMING_SNAKE_CASE           =    BatchEncoding()
																	SCREAMING_SNAKE_CASE           =    input_ids
																	SCREAMING_SNAKE_CASE           =    attention_mask

												if query_images is not None:
																	SCREAMING_SNAKE_CASE           =    BatchEncoding()
																	SCREAMING_SNAKE_CASE           =    self.image_processor(
																	    lowercase_		,							return_tensors=lowercase_		,							**lowercase_ ).pixel_values
																	SCREAMING_SNAKE_CASE           =    query_pixel_values

												if images is not None:
																	SCREAMING_SNAKE_CASE           =    self.image_processor(lowercase_		,							return_tensors=lowercase_		,							**lowercase_ )

												if text is not None and images is not None:
																	SCREAMING_SNAKE_CASE           =    image_features.pixel_values
																	return encoding
												elif query_images is not None and images is not None:
																	SCREAMING_SNAKE_CASE           =    image_features.pixel_values
																	return encoding
												elif text is not None or query_images is not None:
																	return encoding
												else:
																	return BatchEncoding(data=dict(**lowercase_ )		,							tensor_type=lowercase_ )




							def 		__snake_case(  self				:   List[Any]		,							*_UpperCamelCase				:   str		,							**_UpperCamelCase				:   int )   ->			str:



												'''simple docstring'''

												return self.image_processor.post_process(*lowercase_		,							**lowercase_ )




							def 		__snake_case(  self				:   Dict		,							*_UpperCamelCase				:   str		,							**_UpperCamelCase				:   List[str] )   ->			Optional[Any]:



												'''simple docstring'''

												return self.image_processor.post_process_object_detection(*lowercase_		,							**lowercase_ )




							def 		__snake_case(  self				:   Union[str, Any]		,							*_UpperCamelCase				:   Dict		,							**_UpperCamelCase				:   Dict )   ->			Tuple:



												'''simple docstring'''

												return self.image_processor.post_process_image_guided_detection(*lowercase_		,							**lowercase_ )




							def 		__snake_case(  self				:   str		,							*_UpperCamelCase				:   int		,							**_UpperCamelCase				:   List[str] )   ->			List[Any]:



												'''simple docstring'''

												return self.tokenizer.batch_decode(*lowercase_		,							**lowercase_ )




							def 		__snake_case(  self				:   List[str]		,							*_UpperCamelCase				:   Optional[int]		,							**_UpperCamelCase				:   Optional[int] )   ->			str:



												'''simple docstring'''

												return self.tokenizer.decode(*lowercase_		,							**lowercase_ )




							@property
							def 		__snake_case(  self				:   Dict )   ->			List[Any]:



												'''simple docstring'''

												warnings.warn(
												    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."		,							lowercase_		,							)
												return self.image_processor_class





							@property
							def 		__snake_case(  self				:   List[Any] )   ->			Dict:



												'''simple docstring'''

												warnings.warn(
												    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."		,							lowercase_		,							)
												return self.image_processor





import functools
import operator

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


_lowerCamelCase   :				int     			=						logging.get_logger(__name__)

_lowerCamelCase   :				Union[str, Any]     			=						{
    '''microsoft/unispeech-sat-base-100h-libri-ft''': (
        '''https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json'''
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}


class   lowercase      (       a       ):
							lowercase__  :    Tuple									=							"""unispeech-sat"""




							def __init__(  self				:   str		,							_UpperCamelCase				:   Tuple=32		,							_UpperCamelCase				:   Union[str, Any]=768		,							_UpperCamelCase				:   Tuple=12		,							_UpperCamelCase				:   List[str]=12		,							_UpperCamelCase				:   Tuple=3_072		,							_UpperCamelCase				:   List[str]="gelu"		,							_UpperCamelCase				:   Tuple=0.1		,							_UpperCamelCase				:   Any=0.1		,							_UpperCamelCase				:   Union[str, Any]=0.1		,							_UpperCamelCase				:   Dict=0.0		,							_UpperCamelCase				:   Tuple=0.0		,							_UpperCamelCase				:   Tuple=0.1		,							_UpperCamelCase				:   Optional[Any]=0.1		,							_UpperCamelCase				:   Tuple=0.0_2		,							_UpperCamelCase				:   Optional[int]=1e-5		,							_UpperCamelCase				:   Union[str, Any]="group"		,							_UpperCamelCase				:   Optional[int]="gelu"		,							_UpperCamelCase				:   Tuple=(512, 512, 512, 512, 512, 512, 512)		,							_UpperCamelCase				:   List[str]=(5, 2, 2, 2, 2, 2, 2)		,							_UpperCamelCase				:   Optional[int]=(10, 3, 3, 3, 3, 2, 2)		,							_UpperCamelCase				:   Optional[int]=False		,							_UpperCamelCase				:   Dict=128		,							_UpperCamelCase				:   Optional[int]=16		,							_UpperCamelCase				:   Tuple=False		,							_UpperCamelCase				:   Union[str, Any]=True		,							_UpperCamelCase				:   Optional[Any]=0.0_5		,							_UpperCamelCase				:   Union[str, Any]=10		,							_UpperCamelCase				:   Union[str, Any]=2		,							_UpperCamelCase				:   str=0.0		,							_UpperCamelCase				:   List[Any]=10		,							_UpperCamelCase				:   Optional[int]=0		,							_UpperCamelCase				:   Any=320		,							_UpperCamelCase				:   List[Any]=2		,							_UpperCamelCase				:   str=0.1		,							_UpperCamelCase				:   str=100		,							_UpperCamelCase				:   int=256		,							_UpperCamelCase				:   Optional[Any]=256		,							_UpperCamelCase				:   List[Any]=0.1		,							_UpperCamelCase				:   str="mean"		,							_UpperCamelCase				:   int=False		,							_UpperCamelCase				:   Optional[Any]=False		,							_UpperCamelCase				:   Any=256		,							_UpperCamelCase				:   str=(512, 512, 512, 512, 1_500)		,							_UpperCamelCase				:   List[Any]=(5, 3, 3, 1, 1)		,							_UpperCamelCase				:   Union[str, Any]=(1, 2, 3, 1, 1)		,							_UpperCamelCase				:   Any=512		,							_UpperCamelCase				:   str=0		,							_UpperCamelCase				:   int=1		,							_UpperCamelCase				:   Any=2		,							_UpperCamelCase				:   Optional[Any]=504		,							**_UpperCamelCase				:   str		,							)   ->			int:



												'''simple docstring'''

												super().__init__(**_UpperCamelCase		,							pad_token_id=_UpperCamelCase		,							bos_token_id=_UpperCamelCase		,							eos_token_id=_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    hidden_size
												SCREAMING_SNAKE_CASE           =    feat_extract_norm
												SCREAMING_SNAKE_CASE           =    feat_extract_activation
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    conv_bias
												SCREAMING_SNAKE_CASE           =    num_conv_pos_embeddings
												SCREAMING_SNAKE_CASE           =    num_conv_pos_embedding_groups
												SCREAMING_SNAKE_CASE           =    len(self.conv_dim )
												SCREAMING_SNAKE_CASE           =    num_hidden_layers
												SCREAMING_SNAKE_CASE           =    intermediate_size
												SCREAMING_SNAKE_CASE           =    hidden_act
												SCREAMING_SNAKE_CASE           =    num_attention_heads
												SCREAMING_SNAKE_CASE           =    hidden_dropout
												SCREAMING_SNAKE_CASE           =    attention_dropout
												SCREAMING_SNAKE_CASE           =    activation_dropout
												SCREAMING_SNAKE_CASE           =    feat_proj_dropout
												SCREAMING_SNAKE_CASE           =    final_dropout
												SCREAMING_SNAKE_CASE           =    layerdrop
												SCREAMING_SNAKE_CASE           =    layer_norm_eps
												SCREAMING_SNAKE_CASE           =    initializer_range
												SCREAMING_SNAKE_CASE           =    vocab_size
												SCREAMING_SNAKE_CASE           =    num_clusters
												SCREAMING_SNAKE_CASE           =    do_stable_layer_norm
												SCREAMING_SNAKE_CASE           =    use_weighted_layer_sum

												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
												SCREAMING_SNAKE_CASE           =    apply_spec_augment
												SCREAMING_SNAKE_CASE           =    mask_time_prob
												SCREAMING_SNAKE_CASE           =    mask_time_length
												SCREAMING_SNAKE_CASE           =    mask_time_min_masks
												SCREAMING_SNAKE_CASE           =    mask_feature_prob
												SCREAMING_SNAKE_CASE           =    mask_feature_length
												SCREAMING_SNAKE_CASE           =    mask_feature_min_masks

												# parameters for pretraining with codevector quantized representations
												SCREAMING_SNAKE_CASE           =    num_codevectors_per_group
												SCREAMING_SNAKE_CASE           =    num_codevector_groups
												SCREAMING_SNAKE_CASE           =    contrastive_logits_temperature
												SCREAMING_SNAKE_CASE           =    feat_quantizer_dropout
												SCREAMING_SNAKE_CASE           =    num_negatives
												SCREAMING_SNAKE_CASE           =    codevector_dim
												SCREAMING_SNAKE_CASE           =    proj_codevector_dim
												SCREAMING_SNAKE_CASE           =    diversity_loss_weight

												# ctc loss
												SCREAMING_SNAKE_CASE           =    ctc_loss_reduction
												SCREAMING_SNAKE_CASE           =    ctc_zero_infinity

												# SequenceClassification-specific parameter. Feel free to ignore for other classes.
												SCREAMING_SNAKE_CASE           =    classifier_proj_size

												# XVector-specific parameters. Feel free to ignore for other classes.
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    list(_UpperCamelCase )
												SCREAMING_SNAKE_CASE           =    xvector_output_dim





							@property
							def 		__snake_case(  self				:   Tuple )   ->			str:



												'''simple docstring'''

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




