



"""simple docstring"""






from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	['image_processor', 'tokenizer']
	SCREAMING_SNAKE_CASE          =	'BlipImageProcessor'
	SCREAMING_SNAKE_CASE          =	('BertTokenizer', 'BertTokenizerFast')

	def __init__(     self:		Tuple       ,			_SCREAMING_SNAKE_CASE:		Dict       ,			_SCREAMING_SNAKE_CASE:		str)				->       Tuple:

				"""simple docstring"""

				__lowerCAmelCase      :  int												=       False
				super().__init__(_SCREAMING_SNAKE_CASE       ,			_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  str												=       self.image_processor

	def __call__(     self:		Dict       ,			_SCREAMING_SNAKE_CASE:		ImageInput = None       ,			_SCREAMING_SNAKE_CASE:		Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None       ,			_SCREAMING_SNAKE_CASE:		bool = True       ,			_SCREAMING_SNAKE_CASE:		Union[bool, str, PaddingStrategy] = False       ,			_SCREAMING_SNAKE_CASE:		Union[bool, str, TruncationStrategy] = None       ,			_SCREAMING_SNAKE_CASE:		Optional[int] = None       ,			_SCREAMING_SNAKE_CASE:		int = 0       ,			_SCREAMING_SNAKE_CASE:		Optional[int] = None       ,			_SCREAMING_SNAKE_CASE:		Optional[bool] = None       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = False       ,			_SCREAMING_SNAKE_CASE:		bool = True       ,			_SCREAMING_SNAKE_CASE:		Optional[Union[str, TensorType]] = None       ,			**_SCREAMING_SNAKE_CASE:		Optional[int]       ,			)				->       BatchEncoding:

				"""simple docstring"""

				if images is None and text is None:
							raise ValueError("You have to specify either images or text.")

				# Get only text
				if images is None:
							__lowerCAmelCase      :  Tuple												=       self.tokenizer
							__lowerCAmelCase      :  str												=       self.tokenizer(
							    text=_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE       ,			padding=_SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			max_length=_SCREAMING_SNAKE_CASE       ,			stride=_SCREAMING_SNAKE_CASE       ,			pad_to_multiple_of=_SCREAMING_SNAKE_CASE       ,			return_attention_mask=_SCREAMING_SNAKE_CASE       ,			return_overflowing_tokens=_SCREAMING_SNAKE_CASE       ,			return_special_tokens_mask=_SCREAMING_SNAKE_CASE       ,			return_offsets_mapping=_SCREAMING_SNAKE_CASE       ,			return_token_type_ids=_SCREAMING_SNAKE_CASE       ,			return_length=_SCREAMING_SNAKE_CASE       ,			verbose=_SCREAMING_SNAKE_CASE       ,			return_tensors=_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE       ,			)
							return text_encoding

				# add pixel_values
				__lowerCAmelCase      :  List[str]												=       self.image_processor(_SCREAMING_SNAKE_CASE       ,			return_tensors=_SCREAMING_SNAKE_CASE)

				if text is not None:
							__lowerCAmelCase      :  Dict												=       self.tokenizer(
							    text=_SCREAMING_SNAKE_CASE       ,			add_special_tokens=_SCREAMING_SNAKE_CASE       ,			padding=_SCREAMING_SNAKE_CASE       ,			truncation=_SCREAMING_SNAKE_CASE       ,			max_length=_SCREAMING_SNAKE_CASE       ,			stride=_SCREAMING_SNAKE_CASE       ,			pad_to_multiple_of=_SCREAMING_SNAKE_CASE       ,			return_attention_mask=_SCREAMING_SNAKE_CASE       ,			return_overflowing_tokens=_SCREAMING_SNAKE_CASE       ,			return_special_tokens_mask=_SCREAMING_SNAKE_CASE       ,			return_offsets_mapping=_SCREAMING_SNAKE_CASE       ,			return_token_type_ids=_SCREAMING_SNAKE_CASE       ,			return_length=_SCREAMING_SNAKE_CASE       ,			verbose=_SCREAMING_SNAKE_CASE       ,			return_tensors=_SCREAMING_SNAKE_CASE       ,			**_SCREAMING_SNAKE_CASE       ,			)
				else:
							__lowerCAmelCase      :  Union[str, Any]												=       None

				if text_encoding is not None:
							encoding_image_processor.update(_SCREAMING_SNAKE_CASE)

				return encoding_image_processor

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int]       ,			*_SCREAMING_SNAKE_CASE:		Dict       ,			**_SCREAMING_SNAKE_CASE:		List[Any])				->       int:

				"""simple docstring"""

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

	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any]       ,			*_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			**_SCREAMING_SNAKE_CASE:		Optional[Any])				->       Optional[int]:

				"""simple docstring"""

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







	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  Dict												=       self.tokenizer.model_input_names
				__lowerCAmelCase      :  List[str]												=       self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))




"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


__snake_case							:   Optional[int]      =    logging.get_logger(__name__)



class 			A__   (  __SCREAMING_SNAKE_CASE  ,		__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	'maskformer-swin'

	SCREAMING_SNAKE_CASE          =	{
	    'num_attention_heads': 'num_heads',
	    'num_hidden_layers': 'num_layers',
	}

	def __init__(     self:		Optional[int]       ,			_SCREAMING_SNAKE_CASE:		int=224       ,			_SCREAMING_SNAKE_CASE:		Tuple=4       ,			_SCREAMING_SNAKE_CASE:		int=3       ,			_SCREAMING_SNAKE_CASE:		List[Any]=96       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=[2, 2, 6, 2]       ,			_SCREAMING_SNAKE_CASE:		Any=[3, 6, 12, 24]       ,			_SCREAMING_SNAKE_CASE:		List[str]=7       ,			_SCREAMING_SNAKE_CASE:		List[str]=4.0       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=True       ,			_SCREAMING_SNAKE_CASE:		Tuple=0.0       ,			_SCREAMING_SNAKE_CASE:		Any=0.0       ,			_SCREAMING_SNAKE_CASE:		Any=0.1       ,			_SCREAMING_SNAKE_CASE:		str="gelu"       ,			_SCREAMING_SNAKE_CASE:		Tuple=False       ,			_SCREAMING_SNAKE_CASE:		Union[str, Any]=0.02       ,			_SCREAMING_SNAKE_CASE:		str=1e-5       ,			_SCREAMING_SNAKE_CASE:		Optional[int]=None       ,			_SCREAMING_SNAKE_CASE:		str=None       ,			**_SCREAMING_SNAKE_CASE:		Union[str, Any]       ,			)				->       List[str]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  int												=       image_size
				__lowerCAmelCase      :  Any												=       patch_size
				__lowerCAmelCase      :  Tuple												=       num_channels
				__lowerCAmelCase      :  Any												=       embed_dim
				__lowerCAmelCase      :  Any												=       depths
				__lowerCAmelCase      :  Dict												=       len(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  List[Any]												=       num_heads
				__lowerCAmelCase      :  Tuple												=       window_size
				__lowerCAmelCase      :  Dict												=       mlp_ratio
				__lowerCAmelCase      :  Any												=       qkv_bias
				__lowerCAmelCase      :  Union[str, Any]												=       hidden_dropout_prob
				__lowerCAmelCase      :  int												=       attention_probs_dropout_prob
				__lowerCAmelCase      :  Tuple												=       drop_path_rate
				__lowerCAmelCase      :  int												=       hidden_act
				__lowerCAmelCase      :  Optional[int]												=       use_absolute_embeddings
				__lowerCAmelCase      :  List[str]												=       layer_norm_eps
				__lowerCAmelCase      :  Any												=       initializer_range
				# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
				# this indicates the channel dimension after the last stage of the model
				__lowerCAmelCase      :  Optional[Any]												=       int(embed_dim * 2 ** (len(_SCREAMING_SNAKE_CASE) - 1))
				__lowerCAmelCase      :  Any												=       ["stem"] + [F"""stage{idx}""" for idx in range(1       ,			len(_SCREAMING_SNAKE_CASE) + 1)]
				__lowerCAmelCase						,	__lowerCAmelCase      :  List[str]												=       get_aligned_output_features_output_indices(
				    out_features=_SCREAMING_SNAKE_CASE       ,			out_indices=_SCREAMING_SNAKE_CASE       ,			stage_names=self.stage_names)