



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 					_A (			_UpperCAmelCase					):
       UpperCamelCase__						:					List[Any]		      =		['image_processor', 'tokenizer']
       UpperCamelCase__						:					Any		      =		'OwlViTImageProcessor'
       UpperCamelCase__						:					int		      =		('CLIPTokenizer', 'CLIPTokenizerFast')



       def __init__(	self							:  Optional[int]  ,	__SCREAMING_SNAKE_CASE							:  Any=None  ,	__SCREAMING_SNAKE_CASE							:  Optional[int]=None  ,	**__SCREAMING_SNAKE_CASE							:  List[str]):


           '''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.'''  ,	__UpperCamelCase  ,	)
               __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__(__UpperCamelCase  ,	__UpperCamelCase)



       def __call__(	self							:  str  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]=None  ,	__SCREAMING_SNAKE_CASE							:  List[str]=None  ,	__SCREAMING_SNAKE_CASE							:  Optional[Any]=None  ,	__SCREAMING_SNAKE_CASE							:  Any="max_length"  ,	__SCREAMING_SNAKE_CASE							:  List[str]="np"  ,	**__SCREAMING_SNAKE_CASE							:  Dict):


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

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

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

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

                       __a		 =       self.tokenizer(__UpperCamelCase  ,	padding=__UpperCamelCase  ,	return_tensors=__UpperCamelCase  ,	**__UpperCamelCase)
                       encodings.append(__UpperCamelCase)
               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(
                   __UpperCamelCase  ,	return_tensors=__UpperCamelCase  ,	**__UpperCamelCase).pixel_values
               __a		 =       query_pixel_values

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

           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(**__UpperCamelCase)  ,	tensor_type=__UpperCamelCase)



       def 	_lowerCamelCase    (	self							:  Optional[int]  ,	*__SCREAMING_SNAKE_CASE							:  Dict  ,	**__SCREAMING_SNAKE_CASE							:  Optional[int]):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  Optional[Any]  ,	*__SCREAMING_SNAKE_CASE							:  Union[str, Any]  ,	**__SCREAMING_SNAKE_CASE							:  Any):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  Union[str, Any]  ,	*__SCREAMING_SNAKE_CASE							:  Optional[int]  ,	**__SCREAMING_SNAKE_CASE							:  List[str]):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  Optional[int]  ,	*__SCREAMING_SNAKE_CASE							:  List[Any]  ,	**__SCREAMING_SNAKE_CASE							:  Union[str, Any]):


           '''simple docstring'''

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



       def 	_lowerCamelCase    (	self							:  Any  ,	*__SCREAMING_SNAKE_CASE							:  Tuple  ,	**__SCREAMING_SNAKE_CASE							:  Dict):


           '''simple docstring'''

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



       @property
       def 	_lowerCamelCase    (	self							:  Union[str, Any]):


           '''simple docstring'''

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





       @property
       def 	_lowerCamelCase    (	self							:  Dict):


           '''simple docstring'''

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










from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__snake_case		:Union[str, Any]   	=  {'''configuration_vit''': ['''VIT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTConfig''', '''ViTOnnxConfig''']}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:List[str]   	=  ['''ViTFeatureExtractor''']
 __snake_case		:Optional[Any]   	=  ['''ViTImageProcessor''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:str   	=  [
     '''VIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''ViTForImageClassification''',
     '''ViTForMaskedImageModeling''',
     '''ViTModel''',
     '''ViTPreTrainedModel''',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:Tuple   	=  [
     '''TFViTForImageClassification''',
     '''TFViTModel''',
     '''TFViTPreTrainedModel''',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __snake_case		:Tuple   	=  [
     '''FlaxViTForImageClassification''',
     '''FlaxViTModel''',
     '''FlaxViTPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_vit import ViTFeatureExtractor
  from .image_processing_vit import ViTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_vit import (
      VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      ViTForImageClassification,
      ViTForMaskedImageModeling,
      ViTModel,
      ViTPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
 import sys

 __snake_case		:Optional[int]   	=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





