




'''simple docstring'''





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 			_snake_case		(     lowercase_							):
			lowerCAmelCase_					:				str							=   ["image_processor", "tokenizer"]
			lowerCAmelCase_					:				str							=   "OwlViTImageProcessor"
			lowerCAmelCase_					:				Union[str, Any]							=   ("CLIPTokenizer", "CLIPTokenizerFast")




			def __init__( self    ,							a__=None    ,							a__=None    ,							**a__							)    ->    Optional[int]:

										'''simple docstring'''




										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."    ,							a__    ,							)
																	snake_case_      =				kwargs.pop("feature_extractor"							)

										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__(a__    ,							a__							)




			def __call__( self    ,							a__=None    ,							a__=None    ,							a__=None    ,							a__="max_length"    ,							a__="np"    ,							**a__							)    ->    Union[str, 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(a__    ,							a__							) or (isinstance(a__    ,							a__							) and not isinstance(text[0]    ,							a__							)):
																								snake_case_      =				[self.tokenizer(a__    ,							padding=a__    ,							return_tensors=a__    ,							**a__							)]

																	elif isinstance(a__    ,							a__							) and isinstance(text[0]    ,							a__							):
																								snake_case_      =				[]

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

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

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

																	if return_tensors == "np":
																								snake_case_      =				np.concatenate([encoding["input_ids"] for encoding in encodings]    ,							axis=0							)
																								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

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

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

																								snake_case_      =				torch.cat([encoding["input_ids"] for encoding in encodings]    ,							dim=0							)
																								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

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

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

																	snake_case_      =				BatchEncoding()
																	snake_case_      =				input_ids
																	snake_case_      =				attention_mask

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

										if images is not None:
																	snake_case_      =				self.image_processor(a__    ,							return_tensors=a__    ,							**a__							)

										if text is not None and images is not None:
																	snake_case_      =				image_features.pixel_values
																	return encoding
										elif query_images is not None and images is not None:
																	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(**a__							)    ,							tensor_type=a__							)




			def        lowerCAmelCase__    ( self    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




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




			def        lowerCAmelCase__    ( self    ,							*a__    ,							**a__							)    ->    Tuple:

										'''simple docstring'''




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




			def        lowerCAmelCase__    ( self    ,							*a__    ,							**a__							)    ->    List[str]:

										'''simple docstring'''




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




			def        lowerCAmelCase__    ( self    ,							*a__    ,							**a__							)    ->    Union[str, Any]:

										'''simple docstring'''




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




			def        lowerCAmelCase__    ( self    ,							*a__    ,							**a__							)    ->    Dict:

										'''simple docstring'''




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




			@property
			def        lowerCAmelCase__    ( self							)    ->    int:

										'''simple docstring'''




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




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

										'''simple docstring'''




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










'''simple docstring'''





from typing import TYPE_CHECKING

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


_SCREAMING_SNAKE_CASE							:       Optional[int]						=			{
    "configuration_canine": ["CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP", "CanineConfig"],
    "tokenization_canine": ["CanineTokenizer"],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		_SCREAMING_SNAKE_CASE							:       Dict						=			[
		    "CANINE_PRETRAINED_MODEL_ARCHIVE_LIST",
		    "CanineForMultipleChoice",
		    "CanineForQuestionAnswering",
		    "CanineForSequenceClassification",
		    "CanineForTokenClassification",
		    "CanineLayer",
		    "CanineModel",
		    "CaninePreTrainedModel",
		    "load_tf_weights_in_canine",
		]


if TYPE_CHECKING:
		from .configuration_canine import CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP, CanineConfig
		from .tokenization_canine import CanineTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_canine import (
				    CANINE_PRETRAINED_MODEL_ARCHIVE_LIST,
				    CanineForMultipleChoice,
				    CanineForQuestionAnswering,
				    CanineForSequenceClassification,
				    CanineForTokenClassification,
				    CanineLayer,
				    CanineModel,
				    CaninePreTrainedModel,
				    load_tf_weights_in_canine,
				)


else:
		import sys

		_SCREAMING_SNAKE_CASE							:       int						=			_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




