






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  lowerCAmelCase_       (				snake_case__					):
							UpperCamelCase_		:Tuple		      =    ['image_processor', 'tokenizer']
							UpperCamelCase_		:Optional[int]		      =    'OwlViTImageProcessor'
							UpperCamelCase_		:int		      =    ('CLIPTokenizer', 'CLIPTokenizerFast')




							def __init__(   self     :   Union[str, Any] ,							SCREAMING_SNAKE_CASE_     :   Dict=None ,							SCREAMING_SNAKE_CASE_     :   Optional[int]=None ,							**SCREAMING_SNAKE_CASE_     :   int	):
											lowerCAmelCase__      			=						None
											if "feature_extractor" in kwargs:
															warnings.warn(
															    '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
															    ''' instead.''' ,							SCREAMING_SNAKE_CASE_ ,							)
															lowerCAmelCase__      			=						kwargs.pop('''feature_extractor'''	)

											lowerCAmelCase__      			=						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__(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	)




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

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

															elif isinstance(SCREAMING_SNAKE_CASE_ ,							SCREAMING_SNAKE_CASE_	) and isinstance(text[0] ,							SCREAMING_SNAKE_CASE_	):
																			lowerCAmelCase__      			=						[]

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

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

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

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

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

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

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

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

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

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

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

															lowerCAmelCase__      			=						BatchEncoding()
															lowerCAmelCase__      			=						input_ids
															lowerCAmelCase__      			=						attention_mask

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

											if images is not None:
															lowerCAmelCase__      			=						self.image_processor(SCREAMING_SNAKE_CASE_ ,							return_tensors=SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)

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




							def 						__snake_case					(   self     :   str ,							*SCREAMING_SNAKE_CASE_     :   List[str] ,							**SCREAMING_SNAKE_CASE_     :   Tuple	):
											return self.image_processor.post_process(*SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   List[Any] ,							*SCREAMING_SNAKE_CASE_     :   Dict ,							**SCREAMING_SNAKE_CASE_     :   List[Any]	):
											return self.image_processor.post_process_object_detection(*SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Union[str, Any] ,							*SCREAMING_SNAKE_CASE_     :   Union[str, Any] ,							**SCREAMING_SNAKE_CASE_     :   Optional[Any]	):
											return self.image_processor.post_process_image_guided_detection(*SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   Union[str, Any] ,							*SCREAMING_SNAKE_CASE_     :   Tuple ,							**SCREAMING_SNAKE_CASE_     :   Optional[int]	):
											return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)




							def 						__snake_case					(   self     :   str ,							*SCREAMING_SNAKE_CASE_     :   Any ,							**SCREAMING_SNAKE_CASE_     :   Dict	):
											return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_ ,							**SCREAMING_SNAKE_CASE_	)




							@property
							def 						__snake_case					(   self     :   Optional[Any]	):
											warnings.warn(
											    '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.''' ,							SCREAMING_SNAKE_CASE_ ,							)
											return self.image_processor_class




							@property
							def 						__snake_case					(   self     :   Union[str, Any]	):
											warnings.warn(
											    '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.''' ,							SCREAMING_SNAKE_CASE_ ,							)
											return self.image_processor













from typing import TYPE_CHECKING

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


_UpperCAmelCase			:		List[Any]   				=    {
    "configuration_mobilenet_v2": [
        "MOBILENET_V2_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "MobileNetV2Config",
        "MobileNetV2OnnxConfig",
    ],
}

try:
			if not is_vision_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_UpperCAmelCase			:		str   				=    ["MobileNetV2FeatureExtractor"]
			_UpperCAmelCase			:		Union[str, Any]   				=    ["MobileNetV2ImageProcessor"]


try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_UpperCAmelCase			:		Any   				=    [
			    "MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "MobileNetV2ForImageClassification",
			    "MobileNetV2ForSemanticSegmentation",
			    "MobileNetV2Model",
			    "MobileNetV2PreTrainedModel",
			    "load_tf_weights_in_mobilenet_v2",
			]


if TYPE_CHECKING:
			from .configuration_mobilenet_va import (
			    MOBILENET_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    MobileNetVaConfig,
			    MobileNetVaOnnxConfig,
			)

			try:
						if not is_vision_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .feature_extraction_mobilenet_va import MobileNetVaFeatureExtractor
						from .image_processing_mobilenet_va import MobileNetVaImageProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_mobilenet_va import (
						    MOBILENET_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
						    MobileNetVaForImageClassification,
						    MobileNetVaForSemanticSegmentation,
						    MobileNetVaModel,
						    MobileNetVaPreTrainedModel,
						    load_tf_weights_in_mobilenet_va,
						)


else:
			import sys

			_UpperCAmelCase			:		Dict   				=    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





