
from typing import Dict, Iterable, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


snake_case					:						Optional[Any]				 =    logging.get_logger(__name__)





class  _snake_case   (	a_							):
			UpperCamelCase__        =       ['pixel_values']







			def __init__(							self		,  _a = True		,  _a = None		,  _a = PILImageResampling.BICUBIC		,  _a = True		,  _a = None		,  _a = True		,  _a = 1 / 255		,  _a = True		,  _a = IMAGENET_DEFAULT_MEAN		,  _a = IMAGENET_DEFAULT_STD		,  **_a		,  ):
				super().__init__(**__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						Optional[int]        =	size if size is not None else {"shortest_edge": 224}
				__magic_name__						:						Optional[Any]        =	get_size_dict(__SCREAMING_SNAKE_CASE		,  default_to_square=__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						List[str]        =	crop_size if crop_size is not None else {"height": 224, "width": 224}
				__magic_name__						:						Union[str, Any]        =	get_size_dict(__SCREAMING_SNAKE_CASE		,  param_name="crop_size"						)

				__magic_name__						:						List[Any]        =	do_resize
				__magic_name__						:						Optional[int]        =	size
				__magic_name__						:						List[str]        =	resample
				__magic_name__						:						int        =	do_center_crop
				__magic_name__						:						List[Any]        =	crop_size
				__magic_name__						:						Union[str, Any]        =	do_rescale
				__magic_name__						:						List[str]        =	rescale_factor
				__magic_name__						:						Optional[Any]        =	do_normalize
				__magic_name__						:						Tuple        =	image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
				__magic_name__						:						Tuple        =	image_std if image_std is not None else IMAGENET_DEFAULT_STD







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a		,  _a = PILImageResampling.BICUBIC		,  _a = None		,  **_a		,  ):
				__magic_name__						:						Union[str, Any]        =	get_size_dict(__SCREAMING_SNAKE_CASE		,  default_to_square=__SCREAMING_SNAKE_CASE						)
				# size_dict is a dict with either keys "height" and "width" or "shortest_edge"
				if "shortest_edge" in size:
					__magic_name__						:						List[Any]        =	int((256 / 224) * size["shortest_edge"]						)
					__magic_name__						:						Dict        =	get_resize_output_image_size(__SCREAMING_SNAKE_CASE		,  size=__SCREAMING_SNAKE_CASE		,  default_to_square=__SCREAMING_SNAKE_CASE						)
					__magic_name__						:						int        =	{"height": output_size[0], "width": output_size[1]}
				if "height" not in size_dict or "width" not in size_dict:
					raise ValueError(
					    f'''Size dict must have keys \'height\' and \'width\' or \'shortest_edge\'. Got {size_dict.keys()}'''						)
				return resize(
				    __SCREAMING_SNAKE_CASE		,  size=(size_dict["height"], size_dict["width"])		,  resample=__SCREAMING_SNAKE_CASE		,  data_format=__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a		,  _a = None		,  **_a		,  ):
				__magic_name__						:						List[str]        =	get_size_dict(__SCREAMING_SNAKE_CASE						)
				if "height" not in size or "width" not in size:
					raise ValueError(f'''Size dict must have keys \'height\' and \'width\'. Got {size.keys()}'''						)
				return center_crop(__SCREAMING_SNAKE_CASE		,  size=(size["height"], size["width"])		,  data_format=__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a		,  _a = None		,  **_a		,  ):
				return rescale(__SCREAMING_SNAKE_CASE		,  scale=__SCREAMING_SNAKE_CASE		,  data_format=__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a		,  _a		,  _a = None		,  **_a		,  ):
				return normalize(__SCREAMING_SNAKE_CASE		,  mean=__SCREAMING_SNAKE_CASE		,  std=__SCREAMING_SNAKE_CASE		,  data_format=__SCREAMING_SNAKE_CASE		,  **__SCREAMING_SNAKE_CASE						)







			def      SCREAMING_SNAKE_CASE       (							self		,  _a		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = None		,  _a = ChannelDimension.FIRST		,  **_a		,  ):
				__magic_name__						:						int        =	do_resize if do_resize is not None else self.do_resize
				__magic_name__						:						Any        =	resample if resample is not None else self.resample
				__magic_name__						:						Dict        =	do_center_crop if do_center_crop is not None else self.do_center_crop
				__magic_name__						:						Optional[int]        =	do_rescale if do_rescale is not None else self.do_rescale
				__magic_name__						:						List[str]        =	rescale_factor if rescale_factor is not None else self.rescale_factor
				__magic_name__						:						List[str]        =	do_normalize if do_normalize is not None else self.do_normalize
				__magic_name__						:						Optional[Any]        =	image_mean if image_mean is not None else self.image_mean
				__magic_name__						:						Tuple        =	image_std if image_std is not None else self.image_std

				__magic_name__						:						Optional[int]        =	size if size is not None else self.size
				__magic_name__						:						Optional[int]        =	get_size_dict(__SCREAMING_SNAKE_CASE		,  default_to_square=__SCREAMING_SNAKE_CASE						)
				__magic_name__						:						int        =	crop_size if crop_size is not None else self.crop_size
				__magic_name__						:						Optional[Any]        =	get_size_dict(__SCREAMING_SNAKE_CASE		,  param_name="crop_size"						)

				__magic_name__						:						Any        =	make_list_of_images(__SCREAMING_SNAKE_CASE						)

				if not valid_images(__SCREAMING_SNAKE_CASE						):
					raise ValueError(
					    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
					    "torch.Tensor, tf.Tensor or jax.ndarray."						)

				if do_resize and size is None:
					raise ValueError("Size must be specified if do_resize is True."						)

				if do_center_crop and crop_size is None:
					raise ValueError("Crop size must be specified if do_center_crop is True."						)

				if do_rescale and rescale_factor is None:
					raise ValueError("Rescale factor must be specified if do_rescale is True."						)

				if do_normalize and (image_mean is None or image_std is None):
					raise ValueError("Image mean and std must be specified if do_normalize is True."						)

				# All transformations expect numpy arrays.
				__magic_name__						:						Dict        =	[to_numpy_array(__SCREAMING_SNAKE_CASE						) for image in images]

				if do_resize:
					__magic_name__						:						Tuple        =	[self.resize(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						) for image in images]

				if do_center_crop:
					__magic_name__						:						List[str]        =	[self.center_crop(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						) for image in images]

				if do_rescale:
					__magic_name__						:						List[str]        =	[self.rescale(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						) for image in images]

				if do_normalize:
					__magic_name__						:						List[Any]        =	[self.normalize(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						) for image in images]

				__magic_name__						:						str        =	[to_channel_dimension_format(__SCREAMING_SNAKE_CASE		,  __SCREAMING_SNAKE_CASE						) for image in images]

				__magic_name__						:						Any        =	{"pixel_values": images}
				return BatchFeature(data=__SCREAMING_SNAKE_CASE		,  tensor_type=__SCREAMING_SNAKE_CASE						)

import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE			:						List[Any]				  =		logging.get_logger(__name__)

SCREAMING_SNAKE_CASE			:						Optional[int]				  =		{
    """Salesforce/blip-vqa-base""": """https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json""",
    """Salesforce/blip-vqa-capfit-large""": (
        """https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-base""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-large""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json"""
    ),
    """Salesforce/blip-itm-base-coco""": """https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-large-coco""": """https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-base-flikr""": """https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json""",
    """Salesforce/blip-itm-large-flikr""": (
        """https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json"""
    ),
}
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_text_model"""

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   str=3_05_24  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=30_72  ,				__SCREAMING_SNAKE_CASE			:   Any=7_68  ,				__SCREAMING_SNAKE_CASE			:   Tuple=12  ,				__SCREAMING_SNAKE_CASE			:   Dict=8  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   int=1E-12  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Tuple=0.0  ,				__SCREAMING_SNAKE_CASE			:   Dict=0.02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=3_05_22  ,				__SCREAMING_SNAKE_CASE			:   Any=2  ,				__SCREAMING_SNAKE_CASE			:   List[str]=0  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=1_02  ,				__SCREAMING_SNAKE_CASE			:   Optional[int]=True  ,				__SCREAMING_SNAKE_CASE			:   Dict=True  ,				**__SCREAMING_SNAKE_CASE			:   str  ,				):
   super().__init__(
       pad_token_id=__SCREAMING_SNAKE_CASE  ,				bos_token_id=__SCREAMING_SNAKE_CASE  ,				eos_token_id=__SCREAMING_SNAKE_CASE  ,				sep_token_id=__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE  ,				)

   __a							=	vocab_size
   __a							=	hidden_size
   __a							=	encoder_hidden_size
   __a							=	intermediate_size
   __a							=	projection_dim
   __a							=	hidden_dropout_prob
   __a							=	num_hidden_layers
   __a							=	num_attention_heads
   __a							=	max_position_embeddings
   __a							=	layer_norm_eps
   __a							=	hidden_act
   __a							=	initializer_range
   __a							=	attention_probs_dropout_prob
   __a							=	is_decoder
   __a							=	use_cache

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   int							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # get the text config dict if we are loading from BlipConfig
   if config_dict.get("model_type"							) == "blip":
    __a							=	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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip_vision_model"""

  def __init__(		self			:   Optional[int]  ,				__SCREAMING_SNAKE_CASE			:   str=7_68  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=30_72  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=5_12  ,				__SCREAMING_SNAKE_CASE			:   int=12  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=12  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=3_84  ,				__SCREAMING_SNAKE_CASE			:   str=16  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]="gelu"  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=1E-5  ,				__SCREAMING_SNAKE_CASE			:   Optional[Any]=0.0  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=1E-10  ,				**__SCREAMING_SNAKE_CASE			:   List[str]  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   __a							=	hidden_size
   __a							=	intermediate_size
   __a							=	projection_dim
   __a							=	num_hidden_layers
   __a							=	num_attention_heads
   __a							=	patch_size
   __a							=	image_size
   __a							=	initializer_range
   __a							=	attention_dropout
   __a							=	layer_norm_eps
   __a							=	hidden_act

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Optional[Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, os.PathLike]  ,				**__SCREAMING_SNAKE_CASE			:   str							):
   cls._set_token_in_kwargs(__SCREAMING_SNAKE_CASE							)

   __a							,  __a							=	cls.get_config_dict(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   # get the vision config dict if we are loading from BlipConfig
   if config_dict.get("model_type"							) == "blip":
    __a							=	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(__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      """blip"""
  _SCREAMING_SNAKE_CASE     					=      True

  def __init__(		self			:   Union[str, Any]  ,				__SCREAMING_SNAKE_CASE			:   Union[str, Any]=None  ,				__SCREAMING_SNAKE_CASE			:   Any=None  ,				__SCREAMING_SNAKE_CASE			:   int=5_12  ,				__SCREAMING_SNAKE_CASE			:   List[Any]=2.65_92  ,				__SCREAMING_SNAKE_CASE			:   Any=2_56  ,				**__SCREAMING_SNAKE_CASE			:   Any  ,				):
   super().__init__(**__SCREAMING_SNAKE_CASE							)

   if text_config is None:
    __a							=	{}
    logger.info("`text_config` is `None`. Initializing the `BlipTextConfig` with default values."							)

   if vision_config is None:
    __a							=	{}
    logger.info("`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values."							)

   __a							=	BlipTextConfig(**__SCREAMING_SNAKE_CASE							)
   __a							=	BlipVisionConfig(**__SCREAMING_SNAKE_CASE							)

   __a							=	self.vision_config.hidden_size

   __a							=	projection_dim
   __a							=	logit_scale_init_value
   __a							=	1.0
   __a							=	0.02
   __a							=	image_text_hidden_size

  @classmethod
  def 		_UpperCAmelCase (		cls			:   Any  ,				__SCREAMING_SNAKE_CASE			:   BlipTextConfig  ,				__SCREAMING_SNAKE_CASE			:   BlipVisionConfig  ,				**__SCREAMING_SNAKE_CASE			:   List[Any]							):
   return cls(text_config=text_config.to_dict()  ,				vision_config=vision_config.to_dict()  ,				**__SCREAMING_SNAKE_CASE							)

  def 		_UpperCAmelCase (		self			:   Union[str, Any]							):
   __a							=	copy.deepcopy(self.__dict__							)
   __a							=	self.text_config.to_dict()
   __a							=	self.vision_config.to_dict()
   __a							=	self.__class__.model_type
   return output


