





import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
	from ...processing_utils import ProcessorMixin
	from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE					=    logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE					=    {
    '''google/owlvit-base-patch32''': '''https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json''',
    '''google/owlvit-base-patch16''': '''https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json''',
    '''google/owlvit-large-patch14''': '''https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json''',
}






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				List[str]											=       "owlvit_text_model"


	def __init__(self     ,_lowerCamelCase=49408     ,_lowerCamelCase=512     ,_lowerCamelCase=2048     ,_lowerCamelCase=12     ,_lowerCamelCase=8     ,_lowerCamelCase=16     ,_lowerCamelCase="quick_gelu"     ,_lowerCamelCase=1E-5     ,_lowerCamelCase=0.0     ,_lowerCamelCase=0.0_2     ,_lowerCamelCase=1.0     ,_lowerCamelCase=0     ,_lowerCamelCase=49406     ,_lowerCamelCase=49407     ,**_lowerCamelCase     ,)							->							Optional[Any]:







				'''simple docstring'''





				super().__init__(pad_token_id=_lowerCamelCase     ,bos_token_id=_lowerCamelCase     ,eos_token_id=_lowerCamelCase     ,**_lowerCamelCase )

				__lowercase										=							vocab_size
				__lowercase										=							hidden_size
				__lowercase										=							intermediate_size
				__lowercase										=							num_hidden_layers
				__lowercase										=							num_attention_heads
				__lowercase										=							max_position_embeddings
				__lowercase										=							hidden_act
				__lowercase										=							layer_norm_eps
				__lowercase										=							attention_dropout
				__lowercase										=							initializer_range
				__lowercase										=							initializer_factor


	@classmethod
	def 						_UpperCAmelCase     (cls     ,_lowerCamelCase     ,**_lowerCamelCase )							->							"PretrainedConfig":







				'''simple docstring'''





				cls._set_token_in_kwargs(_lowerCamelCase )

				__lowercase						,		__lowercase										=							cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase )

				# get the text config dict if we are loading from OwlViTConfig
				if config_dict.get('''model_type''' ) == "owlvit":
							__lowercase										=							config_dict['''text_config''']

				if "model_type" in config_dict and hasattr(cls     ,'''model_type''' ) and config_dict["model_type"] != cls.model_type:
							logger.warning(
							    f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
							    f"{cls.model_type}. This is not supported for all configurations of models and can yield errors." )

				return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase )






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				Tuple											=       "owlvit_vision_model"


	def __init__(self     ,_lowerCamelCase=768     ,_lowerCamelCase=3072     ,_lowerCamelCase=12     ,_lowerCamelCase=12     ,_lowerCamelCase=3     ,_lowerCamelCase=768     ,_lowerCamelCase=32     ,_lowerCamelCase="quick_gelu"     ,_lowerCamelCase=1E-5     ,_lowerCamelCase=0.0     ,_lowerCamelCase=0.0_2     ,_lowerCamelCase=1.0     ,**_lowerCamelCase     ,)							->							Union[str, Any]:







				'''simple docstring'''





				super().__init__(**_lowerCamelCase )

				__lowercase										=							hidden_size
				__lowercase										=							intermediate_size
				__lowercase										=							num_hidden_layers
				__lowercase										=							num_attention_heads
				__lowercase										=							num_channels
				__lowercase										=							image_size
				__lowercase										=							patch_size
				__lowercase										=							hidden_act
				__lowercase										=							layer_norm_eps
				__lowercase										=							attention_dropout
				__lowercase										=							initializer_range
				__lowercase										=							initializer_factor


	@classmethod
	def 						_UpperCAmelCase     (cls     ,_lowerCamelCase     ,**_lowerCamelCase )							->							"PretrainedConfig":







				'''simple docstring'''





				cls._set_token_in_kwargs(_lowerCamelCase )

				__lowercase						,		__lowercase										=							cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase )

				# get the vision config dict if we are loading from OwlViTConfig
				if config_dict.get('''model_type''' ) == "owlvit":
							__lowercase										=							config_dict['''vision_config''']

				if "model_type" in config_dict and hasattr(cls     ,'''model_type''' ) and config_dict["model_type"] != cls.model_type:
							logger.warning(
							    f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
							    f"{cls.model_type}. This is not supported for all configurations of models and can yield errors." )

				return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase )






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	a    :				List[Any]											=       "owlvit"
	a    :				str											=       True


	def __init__(self     ,_lowerCamelCase=None     ,_lowerCamelCase=None     ,_lowerCamelCase=512     ,_lowerCamelCase=2.6_5_9_2     ,_lowerCamelCase=True     ,**_lowerCamelCase     ,)							->							List[Any]:







				'''simple docstring'''





				super().__init__(**_lowerCamelCase )

				if text_config is None:
							__lowercase										=							{}
							logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.''' )

				if vision_config is None:
							__lowercase										=							{}
							logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.''' )

				__lowercase										=							OwlViTTextConfig(**_lowerCamelCase )
				__lowercase										=							OwlViTVisionConfig(**_lowerCamelCase )

				__lowercase										=							projection_dim
				__lowercase										=							logit_scale_init_value
				__lowercase										=							return_dict
				__lowercase										=							1.0


	@classmethod
	def 						_UpperCAmelCase     (cls     ,_lowerCamelCase     ,**_lowerCamelCase )							->							"PretrainedConfig":







				'''simple docstring'''





				cls._set_token_in_kwargs(_lowerCamelCase )

				__lowercase						,		__lowercase										=							cls.get_config_dict(_lowerCamelCase     ,**_lowerCamelCase )

				if "model_type" in config_dict and hasattr(cls     ,'''model_type''' ) and config_dict["model_type"] != cls.model_type:
							logger.warning(
							    f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
							    f"{cls.model_type}. This is not supported for all configurations of models and can yield errors." )

				return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase )


	@classmethod
	def 						_UpperCAmelCase     (cls     ,_lowerCamelCase     ,_lowerCamelCase     ,**_lowerCamelCase )							->							List[Any]:







				'''simple docstring'''





				__lowercase										=							{}
				__lowercase										=							text_config
				__lowercase										=							vision_config

				return cls.from_dict(_lowerCamelCase     ,**_lowerCamelCase )


	def 						_UpperCAmelCase     (self )							->							Dict:







				'''simple docstring'''





				__lowercase										=							copy.deepcopy(self.__dict__ )
				__lowercase										=							self.text_config.to_dict()
				__lowercase										=							self.vision_config.to_dict()
				__lowercase										=							self.__class__.model_type
				return output






class 							__lowercase       (      lowerCAmelCase__						):







	'''simple docstring'''

	@property
	def 						_UpperCAmelCase     (self )							->							Mapping[str, Mapping[int, str]]:







				'''simple docstring'''





				return OrderedDict(
				    [
				        ('''input_ids''', {0: '''batch''', 1: '''sequence'''}),
				        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
				        ('''attention_mask''', {0: '''batch''', 1: '''sequence'''}),
				    ] )


	@property
	def 						_UpperCAmelCase     (self )							->							Mapping[str, Mapping[int, str]]:







				'''simple docstring'''





				return OrderedDict(
				    [
				        ('''logits_per_image''', {0: '''batch'''}),
				        ('''logits_per_text''', {0: '''batch'''}),
				        ('''text_embeds''', {0: '''batch'''}),
				        ('''image_embeds''', {0: '''batch'''}),
				    ] )


	@property
	def 						_UpperCAmelCase     (self )							->							float:







				'''simple docstring'''





				return 1E-4


	def 						_UpperCAmelCase     (self     ,_lowerCamelCase     ,_lowerCamelCase = -1     ,_lowerCamelCase = -1     ,_lowerCamelCase = None     ,)							->							Mapping[str, Any]:







				'''simple docstring'''





				__lowercase										=							super().generate_dummy_inputs(
				    processor.tokenizer     ,batch_size=_lowerCamelCase     ,seq_length=_lowerCamelCase     ,framework=_lowerCamelCase )
				__lowercase										=							super().generate_dummy_inputs(
				    processor.image_processor     ,batch_size=_lowerCamelCase     ,framework=_lowerCamelCase )
				return {**text_input_dict, **image_input_dict}


	@property
	def 						_UpperCAmelCase     (self )							->							int:







				'''simple docstring'''





				return 14












'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_SCREAMING_SNAKE_CASE					=    {
    '''configuration_clipseg''': [
        '''CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPSegConfig''',
        '''CLIPSegTextConfig''',
        '''CLIPSegVisionConfig''',
    ],
    '''processing_clipseg''': ['''CLIPSegProcessor'''],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_SCREAMING_SNAKE_CASE					=    [
	    '''CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''CLIPSegModel''',
	    '''CLIPSegPreTrainedModel''',
	    '''CLIPSegTextModel''',
	    '''CLIPSegVisionModel''',
	    '''CLIPSegForImageSegmentation''',
	]

if TYPE_CHECKING:
	from .configuration_clipseg import (
	    CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    CLIPSegConfig,
	    CLIPSegTextConfig,
	    CLIPSegVisionConfig,
	)
	from .processing_clipseg import CLIPSegProcessor

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_clipseg import (
		    CLIPSEG_PRETRAINED_MODEL_ARCHIVE_LIST,
		    CLIPSegForImageSegmentation,
		    CLIPSegModel,
		    CLIPSegPreTrainedModel,
		    CLIPSegTextModel,
		    CLIPSegVisionModel,
		)

else:
	import sys

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





