
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 (      UpperCamelCase_ ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  ['''image_processor''', '''tokenizer''']
     SCREAMING_SNAKE_CASE_		   =  '''OwlViTImageProcessor'''
     SCREAMING_SNAKE_CASE_		   =  ('''CLIPTokenizer''', '''CLIPTokenizerFast''')






     def __init__(							self						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=None						,						**__SCREAMING_SNAKE_CASE  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   List[str]					=				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						,						)
                 UpperCamelCase__    :   str					=				kwargs.pop('''feature_extractor'''  )

           UpperCamelCase__    :   List[Any]					=				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						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE=None						,						__SCREAMING_SNAKE_CASE="max_length"						,						__SCREAMING_SNAKE_CASE="np"						,						**__SCREAMING_SNAKE_CASE  )  ->   Optional[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(__UpperCamelCase						,						__UpperCamelCase  ) or (isinstance(__UpperCamelCase						,						__UpperCamelCase  ) and not isinstance(text[0]						,						__UpperCamelCase  )):
                       UpperCamelCase__    :   Optional[Any]					=				[self.tokenizer(__UpperCamelCase						,						padding=__UpperCamelCase						,						return_tensors=__UpperCamelCase						,						**__UpperCamelCase  )]

                 elif isinstance(__UpperCamelCase						,						__UpperCamelCase  ) and isinstance(text[0]						,						__UpperCamelCase  ):
                       UpperCamelCase__    :   Optional[int]					=				[]

                       # Maximum number of queries across batch
                       UpperCamelCase__    :   Union[str, Any]					=				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:
                                   UpperCamelCase__    :   int					=				t + [''' '''] * (max_num_queries - len(__UpperCamelCase  ))

                             UpperCamelCase__    :   Optional[int]					=				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":
                       UpperCamelCase__    :   int					=				np.concatenate([encoding['''input_ids'''] for encoding in encodings]						,						axis=0  )
                       UpperCamelCase__    :   Tuple					=				np.concatenate([encoding['''attention_mask'''] for encoding in encodings]						,						axis=0  )

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

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

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

                       UpperCamelCase__    :   Tuple					=				torch.cat([encoding['''input_ids'''] for encoding in encodings]						,						dim=0  )
                       UpperCamelCase__    :   List[Any]					=				torch.cat([encoding['''attention_mask'''] for encoding in encodings]						,						dim=0  )

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

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

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

                 UpperCamelCase__    :   int					=				BatchEncoding()
                 UpperCamelCase__    :   int					=				input_ids
                 UpperCamelCase__    :   Tuple					=				attention_mask

           if query_images is not None:
                 UpperCamelCase__    :   List[Any]					=				BatchEncoding()
                 UpperCamelCase__    :   str					=				self.image_processor(
                     __UpperCamelCase						,						return_tensors=__UpperCamelCase						,						**__UpperCamelCase  ).pixel_values
                 UpperCamelCase__    :   List[Any]					=				query_pixel_values

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

           if text is not None and images is not None:
                 UpperCamelCase__    :   Dict					=				image_features.pixel_values
                 return encoding
           elif query_images is not None and images is not None:
                 UpperCamelCase__    :   List[str]					=				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    __SCREAMING_SNAKE_CASE			(							self						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   Optional[int]:




           """simple docstring"""







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






     def    __SCREAMING_SNAKE_CASE			(							self						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   Optional[Any]:




           """simple docstring"""







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






     def    __SCREAMING_SNAKE_CASE			(							self						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   str:




           """simple docstring"""







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






     def    __SCREAMING_SNAKE_CASE			(							self						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   List[Any]:




           """simple docstring"""







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






     def    __SCREAMING_SNAKE_CASE			(							self						,						*__SCREAMING_SNAKE_CASE						,						**__SCREAMING_SNAKE_CASE  )  ->   str:




           """simple docstring"""







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






     @property
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Optional[int]:




           """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    __SCREAMING_SNAKE_CASE			(							self  )  ->   Any:




           """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_tf_available, is_torch_available


lowerCamelCase      ={"configuration_swin": ["SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "SwinConfig", "SwinOnnxConfig"]}


try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =[
        "SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
        "SwinForImageClassification",
        "SwinForMaskedImageModeling",
        "SwinModel",
        "SwinPreTrainedModel",
        "SwinBackbone",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    lowerCamelCase      =[
        "TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
        "TFSwinForImageClassification",
        "TFSwinForMaskedImageModeling",
        "TFSwinModel",
        "TFSwinPreTrainedModel",
    ]

if TYPE_CHECKING:
    from .configuration_swin import SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinConfig, SwinOnnxConfig

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_swin import (
            SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
            SwinBackbone,
            SwinForImageClassification,
            SwinForMaskedImageModeling,
            SwinModel,
            SwinPreTrainedModel,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_swin import (
            TF_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFSwinForImageClassification,
            TFSwinForMaskedImageModeling,
            TFSwinModel,
            TFSwinPreTrainedModel,
        )

else:
    import sys

    lowerCamelCase      =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


