



'''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 	UpperCAmelCase	(		__a):


 '''simple docstring'''




 __magic_name__					: Any  =      ["image_processor", "tokenizer"]
 __magic_name__					: Optional[Any]  =      "OwlViTImageProcessor"
 __magic_name__					: Optional[Any]  =      ("CLIPTokenizer", "CLIPTokenizerFast")




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



      """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							,  lowerCAmelCase_=None							,  lowerCAmelCase_=None							,  lowerCAmelCase_=None							,  lowerCAmelCase_="max_length"							,  lowerCAmelCase_="np"							,  **lowerCAmelCase_) ->      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       lowercase_  (   self							,  *lowerCAmelCase_							,  **lowerCAmelCase_) ->      int:



      """simple docstring"""







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




 def       lowercase_  (   self							,  *lowerCAmelCase_							,  **lowerCAmelCase_) ->      int:



      """simple docstring"""







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




 def       lowercase_  (   self							,  *lowerCAmelCase_							,  **lowerCAmelCase_) ->      Dict:



      """simple docstring"""







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




 def       lowercase_  (   self							,  *lowerCAmelCase_							,  **lowerCAmelCase_) ->      Optional[int]:



      """simple docstring"""







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




 def       lowercase_  (   self							,  *lowerCAmelCase_							,  **lowerCAmelCase_) ->      Tuple:



      """simple docstring"""







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




 @property
 def       lowercase_  (   self) ->      Union[str, 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       lowercase_  (   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







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase							       =			{
    '''configuration_timesformer''': ['''TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TimesformerConfig'''],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase							       =			[
      '''TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
      '''TimesformerModel''',
      '''TimesformerForVideoClassification''',
      '''TimesformerPreTrainedModel''',
  ]

if TYPE_CHECKING:
  from .configuration_timesformer import TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, TimesformerConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_timesformer import (
        TIMESFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        TimesformerForVideoClassification,
        TimesformerModel,
        TimesformerPreTrainedModel,
    )

else:
  import sys

  lowercase							       =			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)


