


"""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_ ):
    a_    :				Any             =    ['image_processor', 'tokenizer']
    a_    :				List[str]             =    'BlipImageProcessor'
    a_    :				int             =    'AutoTokenizer'
    def __init__( self							:					Optional[Any]							,					SCREAMING_SNAKE_CASE__							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					List[str]				):
          lowerCamelCase__           =		False
          super().__init__(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		self.image_processor
    def __call__( self							:					Tuple							,					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__							:					List[Any]							,					):
          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__           =		self.tokenizer
                lowerCamelCase__           =		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__           =		self.image_processor(SCREAMING_SNAKE_CASE__							,					return_tensors=SCREAMING_SNAKE_CASE__				)

          if text is not None:
                lowerCamelCase__           =		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__           =		None

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

          return encoding_image_processor
    def      _UpperCamelCase       ( self							:					List[str]							,					*SCREAMING_SNAKE_CASE__							:					List[str]							,					**SCREAMING_SNAKE_CASE__							:					str				):
          return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)
    def      _UpperCamelCase       ( self							:					str							,					*SCREAMING_SNAKE_CASE__							:					Dict							,					**SCREAMING_SNAKE_CASE__							:					Optional[int]				):
          return self.tokenizer.decode(*SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)


    @property
    # Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
    def      _UpperCamelCase       ( self							:					Tuple				):
          lowerCamelCase__           =		self.tokenizer.model_input_names
          lowerCamelCase__           =		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


_snake_case          =							logging.get_logger(__name__)

_snake_case          =							{
    "microsoft/swinv2-tiny-patch4-window8-256": (
        "https://huggingface.co/microsoft/swinv2-tiny-patch4-window8-256/resolve/main/config.json"
    ),
}



class   _a      (      SCREAMING_SNAKE_CASE_ ):
    a_    :				Union[str, Any]             =    'swinv2'

    a_    :				Optional[int]             =    {
        'num_attention_heads': 'num_heads',
        'num_hidden_layers': 'num_layers',
    }
    def __init__( self							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					int=2_24							,					SCREAMING_SNAKE_CASE__							:					str=4							,					SCREAMING_SNAKE_CASE__							:					List[Any]=3							,					SCREAMING_SNAKE_CASE__							:					str=96							,					SCREAMING_SNAKE_CASE__							:					Dict=[2, 2, 6, 2]							,					SCREAMING_SNAKE_CASE__							:					Union[str, Any]=[3, 6, 12, 24]							,					SCREAMING_SNAKE_CASE__							:					Tuple=7							,					SCREAMING_SNAKE_CASE__							:					Union[str, Any]=4.0							,					SCREAMING_SNAKE_CASE__							:					List[str]=True							,					SCREAMING_SNAKE_CASE__							:					List[Any]=0.0							,					SCREAMING_SNAKE_CASE__							:					Optional[int]=0.0							,					SCREAMING_SNAKE_CASE__							:					Dict=0.1							,					SCREAMING_SNAKE_CASE__							:					Tuple="gelu"							,					SCREAMING_SNAKE_CASE__							:					Tuple=False							,					SCREAMING_SNAKE_CASE__							:					Any=0.02							,					SCREAMING_SNAKE_CASE__							:					List[Any]=1e-5							,					SCREAMING_SNAKE_CASE__							:					int=32							,					**SCREAMING_SNAKE_CASE__							:					List[str]							,					):
          super().__init__(**SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		image_size
          lowerCamelCase__           =		patch_size
          lowerCamelCase__           =		num_channels
          lowerCamelCase__           =		embed_dim
          lowerCamelCase__           =		depths
          lowerCamelCase__           =		len(SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		num_heads
          lowerCamelCase__           =		window_size
          lowerCamelCase__           =		mlp_ratio
          lowerCamelCase__           =		qkv_bias
          lowerCamelCase__           =		hidden_dropout_prob
          lowerCamelCase__           =		attention_probs_dropout_prob
          lowerCamelCase__           =		drop_path_rate
          lowerCamelCase__           =		hidden_act
          lowerCamelCase__           =		use_absolute_embeddings
          lowerCamelCase__           =		layer_norm_eps
          lowerCamelCase__           =		initializer_range
          lowerCamelCase__           =		encoder_stride
          # we set the hidden_size attribute in order to make Swinv2 work with VisionEncoderDecoderModel
          # this indicates the channel dimension after the last stage of the model
          lowerCamelCase__           =		int(embed_dim * 2 ** (len(SCREAMING_SNAKE_CASE__				) - 1)				)
          lowerCamelCase__           =		(0, 0, 0, 0)



