



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       SCREAMING_SNAKE_CASE	(							lowerCamelCase__    ):
							__lowerCamelCase		:		Union[str, Any]			=['image_processor', 'tokenizer']
							__lowerCamelCase		:		int			='OwlViTImageProcessor'
							__lowerCamelCase		:		Tuple			=('CLIPTokenizer', 'CLIPTokenizerFast')





							def __init__(      self						:						Dict					, __lowercase						:						Any=None					, __lowercase						:						Optional[Any]=None					, **__lowercase						:						Union[str, Any]		):

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

											__a        =						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__(__lowerCamelCase					, __lowerCamelCase		)





							def __call__(      self						:						int					, __lowercase						:						int=None					, __lowercase						:						List[str]=None					, __lowercase						:						Union[str, Any]=None					, __lowercase						:						Any="max_length"					, __lowercase						:						Tuple="np"					, **__lowercase						:						int		):

											'''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(__lowerCamelCase					, __lowerCamelCase		) or (isinstance(__lowerCamelCase					, __lowerCamelCase		) and not isinstance(text[0]					, __lowerCamelCase		)):
																			__a        =						[self.tokenizer(__lowerCamelCase					, padding=__lowerCamelCase					, return_tensors=__lowerCamelCase					, **__lowerCamelCase		)]

															elif isinstance(__lowerCamelCase					, __lowerCamelCase		) and isinstance(text[0]					, __lowerCamelCase		):
																			__a        =						[]

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

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

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

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

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

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

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

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

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

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

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

															__a        =						BatchEncoding()
															__a        =						input_ids
															__a        =						attention_mask

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

											if images is not None:
															__a        =						self.image_processor(__lowerCamelCase					, return_tensors=__lowerCamelCase					, **__lowerCamelCase		)

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





							def   UpperCamelCase_    (      self						:						Union[str, Any]					, *__lowercase						:						int					, **__lowercase						:						Union[str, Any]		):

											'''simple docstring'''
											return self.image_processor.post_process(*__lowerCamelCase					, **__lowerCamelCase		)





							def   UpperCamelCase_    (      self						:						Optional[int]					, *__lowercase						:						int					, **__lowercase						:						Optional[Any]		):

											'''simple docstring'''
											return self.image_processor.post_process_object_detection(*__lowerCamelCase					, **__lowerCamelCase		)





							def   UpperCamelCase_    (      self						:						Union[str, Any]					, *__lowercase						:						int					, **__lowercase						:						str		):

											'''simple docstring'''
											return self.image_processor.post_process_image_guided_detection(*__lowerCamelCase					, **__lowerCamelCase		)





							def   UpperCamelCase_    (      self						:						Union[str, Any]					, *__lowercase						:						Any					, **__lowercase						:						List[Any]		):

											'''simple docstring'''
											return self.tokenizer.batch_decode(*__lowerCamelCase					, **__lowerCamelCase		)





							def   UpperCamelCase_    (      self						:						Any					, *__lowercase						:						Union[str, Any]					, **__lowercase						:						Dict		):

											'''simple docstring'''
											return self.tokenizer.decode(*__lowerCamelCase					, **__lowerCamelCase		)





							@property
							def   UpperCamelCase_    (      self						:						Any		):

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







							@property
							def   UpperCamelCase_    (      self						:						List[Any]		):

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




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


lowerCAmelCase__      		= logging.get_logger(__name__)

lowerCAmelCase__      		= {
    'facebook/vit-mae-base': 'https://huggingface.co/facebook/vit-mae-base/resolve/main/config.json',
    # See all ViT MAE models at https://huggingface.co/models?filter=vit-mae
}







class      lowerCAmelCase__       (				a):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE  			= "vit_mae"


     def __init__(						self ,						__lowerCamelCase=7_6_8 ,						__lowerCamelCase=1_2 ,						__lowerCamelCase=1_2 ,						__lowerCamelCase=3_0_7_2 ,						__lowerCamelCase="gelu" ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0 ,						__lowerCamelCase=0.0_2 ,						__lowerCamelCase=1e-12 ,						__lowerCamelCase=2_2_4 ,						__lowerCamelCase=1_6 ,						__lowerCamelCase=3 ,						__lowerCamelCase=True ,						__lowerCamelCase=1_6 ,						__lowerCamelCase=5_1_2 ,						__lowerCamelCase=8 ,						__lowerCamelCase=2_0_4_8 ,						__lowerCamelCase=0.7_5 ,						__lowerCamelCase=False ,						**__lowerCamelCase ,						)			->				int:
            super().__init__(**__lowerCamelCase)

            _A      :       int				    = hidden_size
            _A      :       List[str]				    = num_hidden_layers
            _A      :       List[Any]				    = num_attention_heads
            _A      :       Optional[Any]				    = intermediate_size
            _A      :       Optional[int]				    = hidden_act
            _A      :       List[Any]				    = hidden_dropout_prob
            _A      :       List[Any]				    = attention_probs_dropout_prob
            _A      :       Union[str, Any]				    = initializer_range
            _A      :       str				    = layer_norm_eps
            _A      :       Any				    = image_size
            _A      :       int				    = patch_size
            _A      :       int				    = num_channels
            _A      :       Dict				    = qkv_bias
            _A      :       Tuple				    = decoder_num_attention_heads
            _A      :       Tuple				    = decoder_hidden_size
            _A      :       List[str]				    = decoder_num_hidden_layers
            _A      :       Optional[Any]				    = decoder_intermediate_size
            _A      :       List[str]				    = mask_ratio
            _A      :       Union[str, Any]				    = norm_pix_loss
