




# Imports
import numpy as np




class 		UpperCamelCase__	:

    '''simple docstring'''



    def __init__(    self     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     )     ->      List[Any]:
           self.set_matricies(red=UpperCamelCase__     ,  green=UpperCamelCase__     ,  blue=UpperCamelCase__     ,  red_edge=UpperCamelCase__     ,  nir=UpperCamelCase__     )







    def     _lowercase     (    self     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     )     ->      Optional[int]:
           if red is not None:
                  lowerCamelCase   :      Any			 =					red
           if green is not None:
                  lowerCamelCase   :      List[str]			 =					green
           if blue is not None:
                  lowerCamelCase   :      str			 =					blue
           if red_edge is not None:
                  lowerCamelCase   :      Tuple			 =					red_edge
           if nir is not None:
                  lowerCamelCase   :      List[str]			 =					nir
           return True







    def     _lowercase     (    self     ,  UpperCamelCase__=""     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     )     ->      List[str]:
           self.set_matricies(red=UpperCamelCase__     ,  green=UpperCamelCase__     ,  blue=UpperCamelCase__     ,  red_edge=UpperCamelCase__     ,  nir=UpperCamelCase__     )
           lowerCamelCase   :      str			 =					{
               "ARVI2": self.arvaa,
               "CCCI": self.ccci,
               "CVI": self.cvi,
               "GLI": self.gli,
               "NDVI": self.ndvi,
               "BNDVI": self.bndvi,
               "redEdgeNDVI": self.red_edge_ndvi,
               "GNDVI": self.gndvi,
               "GBNDVI": self.gbndvi,
               "GRNDVI": self.grndvi,
               "RBNDVI": self.rbndvi,
               "PNDVI": self.pndvi,
               "ATSAVI": self.atsavi,
               "BWDRVI": self.bwdrvi,
               "CIgreen": self.ci_green,
               "CIrededge": self.ci_rededge,
               "CI": self.ci,
               "CTVI": self.ctvi,
               "GDVI": self.gdvi,
               "EVI": self.evi,
               "GEMI": self.gemi,
               "GOSAVI": self.gosavi,
               "GSAVI": self.gsavi,
               "Hue": self.hue,
               "IVI": self.ivi,
               "IPVI": self.ipvi,
               "I": self.i,
               "RVI": self.rvi,
               "MRVI": self.mrvi,
               "MSAVI": self.m_savi,
               "NormG": self.norm_g,
               "NormNIR": self.norm_nir,
               "NormR": self.norm_r,
               "NGRDI": self.ngrdi,
               "RI": self.ri,
               "S": self.s,
               "IF": self._if,
               "DVI": self.dvi,
               "TVI": self.tvi,
               "NDRE": self.ndre,
           }

           try:
                  return funcs[index]()
           except KeyError:
                  print("Index not in the list!"     )
                  return False







    def     _lowercase     (    self     )     ->      Optional[Any]:
           return -0.18 + (1.17 * ((self.nir - self.red) / (self.nir + self.red)))







    def     _lowercase     (    self     )     ->      int:
           return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
               (self.nir - self.red) / (self.nir + self.red)
           )







    def     _lowercase     (    self     )     ->      Optional[Any]:
           return self.nir * (self.red / (self.green**2))







    def     _lowercase     (    self     )     ->      Any:
           return (2 * self.green - self.red - self.blue) / (
               2 * self.green + self.red + self.blue
           )







    def     _lowercase     (    self     )     ->      List[Any]:
           return (self.nir - self.red) / (self.nir + self.red)







    def     _lowercase     (    self     )     ->      Any:
           return (self.nir - self.blue) / (self.nir + self.blue)







    def     _lowercase     (    self     )     ->      Any:
           return (self.redEdge - self.red) / (self.redEdge + self.red)







    def     _lowercase     (    self     )     ->      List[Any]:
           return (self.nir - self.green) / (self.nir + self.green)







    def     _lowercase     (    self     )     ->      Optional[Any]:
           return (self.nir - (self.green + self.blue)) / (
               self.nir + (self.green + self.blue)
           )







    def     _lowercase     (    self     )     ->      Dict:
           return (self.nir - (self.green + self.red)) / (
               self.nir + (self.green + self.red)
           )







    def     _lowercase     (    self     )     ->      str:
           return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))







    def     _lowercase     (    self     )     ->      List[str]:
           return (self.nir - (self.green + self.red + self.blue)) / (
               self.nir + (self.green + self.red + self.blue)
           )







    def     _lowercase     (    self     ,  UpperCamelCase__=0.08     ,  UpperCamelCase__=1.22     ,  UpperCamelCase__=0.03     )     ->      int:
           return a * (
               (self.nir - a * self.red - b)
               / (a * self.nir + self.red - a * b + x * (1 + a**2))
           )







    def     _lowercase     (    self     )     ->      str:
           return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)







    def     _lowercase     (    self     )     ->      Dict:
           return (self.nir / self.green) - 1







    def     _lowercase     (    self     )     ->      List[Any]:
           return (self.nir / self.redEdge) - 1







    def     _lowercase     (    self     )     ->      Optional[int]:
           return (self.red - self.blue) / self.red







    def     _lowercase     (    self     )     ->      Any:
           lowerCamelCase   :      Optional[Any]			 =					self.ndvi()
           return ((ndvi + 0.5) / (abs(ndvi + 0.5     ))) * (abs(ndvi + 0.5     ) ** (1 / 2))







    def     _lowercase     (    self     )     ->      Optional[int]:
           return self.nir - self.green







    def     _lowercase     (    self     )     ->      Tuple:
           return 2.5 * (
               (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
           )







    def     _lowercase     (    self     )     ->      Union[str, Any]:
           lowerCamelCase   :      Any			 =					(2 * (self.nir**2 - self.red**2) + 1.5 * self.nir + 0.5 * self.red) / (
               self.nir + self.red + 0.5
           )
           return n * (1 - 0.25 * n) - (self.red - 0.125) / (1 - self.red)







    def     _lowercase     (    self     ,  UpperCamelCase__=0.16     )     ->      Any:
           return (self.nir - self.green) / (self.nir + self.green + y)







    def     _lowercase     (    self     ,  UpperCamelCase__=0.5     )     ->      Tuple:
           return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)







    def     _lowercase     (    self     )     ->      List[Any]:
           return np.arctan(
               ((2 * self.red - self.green - self.blue) / 30.5) * (self.green - self.blue)     )







    def     _lowercase     (    self     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     )     ->      int:
           return (self.nir - b) / (a * self.red)







    def     _lowercase     (    self     )     ->      Dict:
           return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)







    def     _lowercase     (    self     )     ->      Union[str, Any]:
           return (self.red + self.green + self.blue) / 30.5







    def     _lowercase     (    self     )     ->      int:
           return self.nir / self.red







    def     _lowercase     (    self     )     ->      List[Any]:
           return (self.rvi() - 1) / (self.rvi() + 1)







    def     _lowercase     (    self     )     ->      Optional[Any]:
           return (
               (2 * self.nir + 1)
               - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
           ) / 2







    def     _lowercase     (    self     )     ->      List[Any]:
           return self.green / (self.nir + self.red + self.green)







    def     _lowercase     (    self     )     ->      int:
           return self.nir / (self.nir + self.red + self.green)







    def     _lowercase     (    self     )     ->      Tuple:
           return self.red / (self.nir + self.red + self.green)







    def     _lowercase     (    self     )     ->      Optional[int]:
           return (self.green - self.red) / (self.green + self.red)







    def     _lowercase     (    self     )     ->      Any:
           return (self.red - self.green) / (self.red + self.green)







    def     _lowercase     (    self     )     ->      List[str]:
           lowerCamelCase   :      Union[str, Any]			 =					np.max([np.max(self.red     ), np.max(self.green     ), np.max(self.blue     )]     )
           lowerCamelCase   :      Union[str, Any]			 =					np.min([np.min(self.red     ), np.min(self.green     ), np.min(self.blue     )]     )
           return (max_value - min_value) / max_value







    def     _lowercase     (    self     )     ->      int:
           return (2 * self.red - self.green - self.blue) / (self.green - self.blue)







    def     _lowercase     (    self     )     ->      Optional[int]:
           return self.nir / self.red







    def     _lowercase     (    self     )     ->      Optional[Any]:
           return (self.ndvi() + 0.5) ** (1 / 2)







    def     _lowercase     (    self     )     ->      Dict:
           return (self.nir - self.redEdge) / (self.nir + self.redEdge)












import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


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

SCREAMING_SNAKE_CASE__       :      Dict  =   {
    'salesforce/blip2-opt-2.7b': 'https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json',
}




class 		UpperCamelCase__	(lowerCAmelCase__     ):

    '''simple docstring'''



    lowerCamelCase_      :	Union[str, Any]	     =      """blip_2_vision_model"""







    def __init__(    self     ,  UpperCamelCase__=1408     ,  UpperCamelCase__=6144     ,  UpperCamelCase__=39     ,  UpperCamelCase__=16     ,  UpperCamelCase__=224     ,  UpperCamelCase__=14     ,  UpperCamelCase__="gelu"     ,  UpperCamelCase__=0.00001     ,  UpperCamelCase__=0.0     ,  UpperCamelCase__=1e-10     ,  UpperCamelCase__=True     ,  **UpperCamelCase__     ,  )     ->      Optional[Any]:
           super().__init__(**UpperCamelCase__     )

           lowerCamelCase   :      Dict			 =					hidden_size
           lowerCamelCase   :      Union[str, Any]			 =					intermediate_size
           lowerCamelCase   :      List[str]			 =					num_hidden_layers
           lowerCamelCase   :      List[str]			 =					num_attention_heads
           lowerCamelCase   :      Dict			 =					patch_size
           lowerCamelCase   :      Tuple			 =					image_size
           lowerCamelCase   :      Dict			 =					initializer_range
           lowerCamelCase   :      Union[str, Any]			 =					attention_dropout
           lowerCamelCase   :      Dict			 =					layer_norm_eps
           lowerCamelCase   :      Optional[Any]			 =					hidden_act
           lowerCamelCase   :      str			 =					qkv_bias







    @classmethod
    def     _lowercase     (    cls     ,  UpperCamelCase__     ,  **UpperCamelCase__     )     ->      "PretrainedConfig":
           cls._set_token_in_kwargs(UpperCamelCase__     )

           lowerCamelCase ,      lowerCamelCase   :      List[str]			 =					cls.get_config_dict(UpperCamelCase__     ,  **UpperCamelCase__     )

           # get the vision config dict if we are loading from Blip2Config
           if config_dict.get("model_type"     ) == "blip-2":
                  lowerCamelCase   :      Optional[int]			 =					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(UpperCamelCase__     ,  **UpperCamelCase__     )




class 		UpperCamelCase__	(lowerCAmelCase__     ):

    '''simple docstring'''



    lowerCamelCase_      :	Dict	     =      """blip_2_qformer"""







    def __init__(    self     ,  UpperCamelCase__=3_0522     ,  UpperCamelCase__=768     ,  UpperCamelCase__=12     ,  UpperCamelCase__=12     ,  UpperCamelCase__=3072     ,  UpperCamelCase__="gelu"     ,  UpperCamelCase__=0.1     ,  UpperCamelCase__=0.1     ,  UpperCamelCase__=512     ,  UpperCamelCase__=0.02     ,  UpperCamelCase__=1e-12     ,  UpperCamelCase__=0     ,  UpperCamelCase__="absolute"     ,  UpperCamelCase__=2     ,  UpperCamelCase__=1408     ,  **UpperCamelCase__     ,  )     ->      int:
           super().__init__(pad_token_id=UpperCamelCase__     ,  **UpperCamelCase__     )

           lowerCamelCase   :      Optional[int]			 =					vocab_size
           lowerCamelCase   :      int			 =					hidden_size
           lowerCamelCase   :      Dict			 =					num_hidden_layers
           lowerCamelCase   :      Union[str, Any]			 =					num_attention_heads
           lowerCamelCase   :      int			 =					hidden_act
           lowerCamelCase   :      Optional[Any]			 =					intermediate_size
           lowerCamelCase   :      Dict			 =					hidden_dropout_prob
           lowerCamelCase   :      Dict			 =					attention_probs_dropout_prob
           lowerCamelCase   :      Dict			 =					max_position_embeddings
           lowerCamelCase   :      List[str]			 =					initializer_range
           lowerCamelCase   :      List[str]			 =					layer_norm_eps
           lowerCamelCase   :      int			 =					position_embedding_type
           lowerCamelCase   :      Tuple			 =					cross_attention_frequency
           lowerCamelCase   :      Optional[int]			 =					encoder_hidden_size







    @classmethod
    def     _lowercase     (    cls     ,  UpperCamelCase__     ,  **UpperCamelCase__     )     ->      "PretrainedConfig":
           cls._set_token_in_kwargs(UpperCamelCase__     )

           lowerCamelCase ,      lowerCamelCase   :      str			 =					cls.get_config_dict(UpperCamelCase__     ,  **UpperCamelCase__     )

           # get the qformer config dict if we are loading from Blip2Config
           if config_dict.get("model_type"     ) == "blip-2":
                  lowerCamelCase   :      int			 =					config_dict["qformer_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(UpperCamelCase__     ,  **UpperCamelCase__     )




class 		UpperCamelCase__	(lowerCAmelCase__     ):

    '''simple docstring'''



    lowerCamelCase_      :	List[str]	     =      """blip-2"""
    lowerCamelCase_      :	int	     =      True







    def __init__(    self     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=None     ,  UpperCamelCase__=32     ,  **UpperCamelCase__     )     ->      str:
           super().__init__(**UpperCamelCase__     )

           if vision_config is None:
                  lowerCamelCase   :      List[Any]			 =					{}
                  logger.info("vision_config is None. initializing the Blip2VisionConfig with default values."     )

           if qformer_config is None:
                  lowerCamelCase   :      List[Any]			 =					{}
                  logger.info("qformer_config is None. Initializing the Blip2QFormerConfig with default values."     )

           if text_config is None:
                  lowerCamelCase   :      Any			 =					{}
                  logger.info("text_config is None. Initializing the text config with default values (`OPTConfig`)."     )

           lowerCamelCase   :      Optional[int]			 =					BlipaVisionConfig(**UpperCamelCase__     )
           lowerCamelCase   :      str			 =					BlipaQFormerConfig(**UpperCamelCase__     )
           lowerCamelCase   :      List[str]			 =					text_config["model_type"] if "model_type" in text_config else "opt"
           lowerCamelCase   :      str			 =					CONFIG_MAPPING[text_model_type](**UpperCamelCase__     )

           lowerCamelCase   :      Optional[Any]			 =					self.text_config.tie_word_embeddings
           lowerCamelCase   :      int			 =					self.text_config.is_encoder_decoder

           lowerCamelCase   :      Optional[Any]			 =					num_query_tokens
           lowerCamelCase   :      int			 =					self.vision_config.hidden_size
           lowerCamelCase   :      Tuple			 =					self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
           lowerCamelCase   :      Dict			 =					1.0
           lowerCamelCase   :      List[Any]			 =					0.02







    @classmethod
    def     _lowercase     (    cls     ,  UpperCamelCase__     ,  UpperCamelCase__     ,  UpperCamelCase__     ,  **UpperCamelCase__     ,  )     ->      str:
           return cls(
               vision_config=vision_config.to_dict()     ,  qformer_config=qformer_config.to_dict()     ,  text_config=text_config.to_dict()     ,  **UpperCamelCase__     ,  )







    def     _lowercase     (    self     )     ->      Optional[Any]:
           lowerCamelCase   :      Tuple			 =					copy.deepcopy(self.__dict__     )
           lowerCamelCase   :      Tuple			 =					self.vision_config.to_dict()
           lowerCamelCase   :      int			 =					self.qformer_config.to_dict()
           lowerCamelCase   :      Optional[Any]			 =					self.text_config.to_dict()
           lowerCamelCase   :      int			 =					self.__class__.model_type
           return output






