






# Imports
import numpy as np





class       __a  :







 def __init__(		self :       List[str]							,       SCREAMING_SNAKE_CASE :       Any=None							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=None							,       SCREAMING_SNAKE_CASE :       Any=None							,       SCREAMING_SNAKE_CASE :       Any=None							,       SCREAMING_SNAKE_CASE :       str=None						):


      '''simple docstring'''






      self.set_matricies(red=SCREAMING_SNAKE_CASE							,       green=SCREAMING_SNAKE_CASE							,       blue=SCREAMING_SNAKE_CASE							,       red_edge=SCREAMING_SNAKE_CASE							,       nir=SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       Union[str, Any]							,       SCREAMING_SNAKE_CASE :       Any=None							,       SCREAMING_SNAKE_CASE :       List[str]=None							,       SCREAMING_SNAKE_CASE :       int=None							,       SCREAMING_SNAKE_CASE :       List[str]=None							,       SCREAMING_SNAKE_CASE :       Optional[int]=None						):


      '''simple docstring'''






      if red is not None:
           UpperCamelCase__      :       List[str]	    =  red
      if green is not None:
           UpperCamelCase__      :       int	    =  green
      if blue is not None:
           UpperCamelCase__      :       int	    =  blue
      if red_edge is not None:
           UpperCamelCase__      :       int	    =  red_edge
      if nir is not None:
           UpperCamelCase__      :       Tuple	    =  nir
      return True







 def  __lowercase (		self :       Dict							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=""							,       SCREAMING_SNAKE_CASE :       Optional[Any]=None							,       SCREAMING_SNAKE_CASE :       Any=None							,       SCREAMING_SNAKE_CASE :       Optional[int]=None							,       SCREAMING_SNAKE_CASE :       List[str]=None							,       SCREAMING_SNAKE_CASE :       Optional[Any]=None						):


      '''simple docstring'''






      self.set_matricies(red=SCREAMING_SNAKE_CASE							,       green=SCREAMING_SNAKE_CASE							,       blue=SCREAMING_SNAKE_CASE							,       red_edge=SCREAMING_SNAKE_CASE							,       nir=SCREAMING_SNAKE_CASE						)
      UpperCamelCase__      :       List[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 :       int						):


      '''simple docstring'''






      return -0.1_8 + (1.1_7 * ((self.nir - self.red) / (self.nir + self.red)))







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return ((self.nir - self.redEdge) / (self.nir + self.redEdge)) / (
          (self.nir - self.red) / (self.nir + self.red)
      )







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return self.nir * (self.red / (self.green**2))







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return (2 * self.green - self.red - self.blue) / (
          2 * self.green + self.red + self.blue
      )







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      return (self.nir - self.red) / (self.nir + self.red)







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return (self.nir - self.blue) / (self.nir + self.blue)







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return (self.redEdge - self.red) / (self.redEdge + self.red)







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return (self.nir - self.green) / (self.nir + self.green)







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return (self.nir - (self.green + self.blue)) / (
          self.nir + (self.green + self.blue)
      )







 def  __lowercase (		self :       Dict						):


      '''simple docstring'''






      return (self.nir - (self.green + self.red)) / (
          self.nir + (self.green + self.red)
      )







 def  __lowercase (		self :       Dict						):


      '''simple docstring'''






      return (self.nir - (self.blue + self.red)) / (self.nir + (self.blue + self.red))







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      return (self.nir - (self.green + self.red + self.blue)) / (
          self.nir + (self.green + self.red + self.blue)
      )







 def  __lowercase (		self :       Tuple							,       SCREAMING_SNAKE_CASE :       List[Any]=0.0_8							,       SCREAMING_SNAKE_CASE :       int=1.2_2							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=0.0_3						):


      '''simple docstring'''






      return a * (
          (self.nir - a * self.red - b)
          / (a * self.nir + self.red - a * b + x * (1 + a**2))
      )







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      return (0.1 * self.nir - self.blue) / (0.1 * self.nir + self.blue)







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      return (self.nir / self.green) - 1







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return (self.nir / self.redEdge) - 1







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      return (self.red - self.blue) / self.red







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      UpperCamelCase__      :       Any	    =  self.ndvi()
      return ((ndvi + 0.5) / (abs(ndvi + 0.5						))) * (abs(ndvi + 0.5						) ** (1 / 2))







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      return self.nir - self.green







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      return 2.5 * (
          (self.nir - self.red) / (self.nir + 6 * self.red - 7.5 * self.blue + 1)
      )







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  (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.2_5 * n) - (self.red - 0.1_2_5) / (1 - self.red)







 def  __lowercase (		self :       Any							,       SCREAMING_SNAKE_CASE :       int=0.1_6						):


      '''simple docstring'''






      return (self.nir - self.green) / (self.nir + self.green + y)







 def  __lowercase (		self :       Tuple							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=0.5						):


      '''simple docstring'''






      return ((self.nir - self.green) / (self.nir + self.green + n)) * (1 + n)







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return np.arctan(
          ((2 * self.red - self.green - self.blue) / 3_0.5) * (self.green - self.blue)						)







 def  __lowercase (		self :       List[str]							,       SCREAMING_SNAKE_CASE :       Optional[int]=None							,       SCREAMING_SNAKE_CASE :       List[Any]=None						):


      '''simple docstring'''






      return (self.nir - b) / (a * self.red)







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      return (self.nir / ((self.nir + self.red) / 2)) * (self.ndvi() + 1)







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      return (self.red + self.green + self.blue) / 3_0.5







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      return self.nir / self.red







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      return (self.rvi() - 1) / (self.rvi() + 1)







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return (
          (2 * self.nir + 1)
          - ((2 * self.nir + 1) ** 2 - 8 * (self.nir - self.red)) ** (1 / 2)
      ) / 2







 def  __lowercase (		self :       int						):


      '''simple docstring'''






      return self.green / (self.nir + self.red + self.green)







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      return self.nir / (self.nir + self.red + self.green)







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      return self.red / (self.nir + self.red + self.green)







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return (self.green - self.red) / (self.green + self.red)







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      return (self.red - self.green) / (self.red + self.green)







 def  __lowercase (		self :       List[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[Any]	    =  np.max([np.max(self.red						), np.max(self.green						), np.max(self.blue						)]						)
      UpperCamelCase__      :       Dict	    =  np.min([np.min(self.red						), np.min(self.green						), np.min(self.blue						)]						)
      return (max_value - min_value) / max_value







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      return (2 * self.red - self.green - self.blue) / (self.green - self.blue)







 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      return self.nir / self.red







 def  __lowercase (		self :       Optional[int]						):


      '''simple docstring'''






      return (self.ndvi() + 0.5) ** (1 / 2)







 def  __lowercase (		self :       str						):


      '''simple docstring'''






      return (self.nir - self.redEdge) / (self.nir + self.redEdge)







from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
 from PIL import Image

 from ..image_utils import load_image

if is_torch_available():
 from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
 from ..tf_utils import stable_softmax

lowerCamelCase     :							str    =logging.get_logger(__name__)





@add_end_docstrings(A__	)
class       __a  (   A__	):







 def __init__(		self :       List[str]							,       **SCREAMING_SNAKE_CASE :       Tuple						):


      '''simple docstring'''






      super().__init__(**SCREAMING_SNAKE_CASE						)

      requires_backends(self							,       "vision"						)
      self.check_model_type(
          TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
          if self.framework == "tf"
          else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING						)







 def __call__(		self :       Dict							,       SCREAMING_SNAKE_CASE :       Union[str, List[str], "Image", List["Image"]]							,       **SCREAMING_SNAKE_CASE :       str						):


      '''simple docstring'''






      return super().__call__(SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE						)







 def  __lowercase (		self :       List[str]							,       **SCREAMING_SNAKE_CASE :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       List[Any]	    =  {}
      if "candidate_labels" in kwargs:
           UpperCamelCase__      :       Optional[Any]	    =  kwargs["candidate_labels"]
      if "hypothesis_template" in kwargs:
           UpperCamelCase__      :       int	    =  kwargs["hypothesis_template"]

      return preprocess_params, {}, {}







 def  __lowercase (		self :       List[Any]							,       SCREAMING_SNAKE_CASE :       List[Any]							,       SCREAMING_SNAKE_CASE :       Tuple=None							,       SCREAMING_SNAKE_CASE :       Optional[int]="This is a photo of {}."						):


      '''simple docstring'''






      UpperCamelCase__      :       Dict	    =  load_image(SCREAMING_SNAKE_CASE						)
      UpperCamelCase__      :       List[Any]	    =  self.image_processor(images=[image]							,       return_tensors=self.framework						)
      UpperCamelCase__      :       Any	    =  candidate_labels
      UpperCamelCase__      :       Dict	    =  [hypothesis_template.format(SCREAMING_SNAKE_CASE						) for x in candidate_labels]
      UpperCamelCase__      :       Optional[Any]	    =  self.tokenizer(SCREAMING_SNAKE_CASE							,       return_tensors=self.framework							,       padding=SCREAMING_SNAKE_CASE						)
      UpperCamelCase__      :       List[Any]	    =  [text_inputs]
      return inputs







 def  __lowercase (		self :       int							,       SCREAMING_SNAKE_CASE :       Union[str, Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Tuple	    =  model_inputs.pop("candidate_labels"						)
      UpperCamelCase__      :       List[str]	    =  model_inputs.pop("text_inputs"						)
      if isinstance(text_inputs[0]							,       SCREAMING_SNAKE_CASE						):
           UpperCamelCase__      :       Dict	    =  text_inputs[0]
      else:
           # Batching case.
           UpperCamelCase__      :       Union[str, Any]	    =  text_inputs[0][0]

      UpperCamelCase__      :       Any	    =  self.model(**SCREAMING_SNAKE_CASE							,       **SCREAMING_SNAKE_CASE						)

      UpperCamelCase__      :       Dict	    =  {
          "candidate_labels": candidate_labels,
          "logits": outputs.logits_per_image,
      }
      return model_outputs







 def  __lowercase (		self :       Any							,       SCREAMING_SNAKE_CASE :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       Optional[int]	    =  model_outputs.pop("candidate_labels"						)
      UpperCamelCase__      :       int	    =  model_outputs["logits"][0]
      if self.framework == "pt":
           UpperCamelCase__      :       Dict	    =  logits.softmax(dim=-1						).squeeze(-1						)
           UpperCamelCase__      :       Optional[Any]	    =  probs.tolist()
           if not isinstance(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						):
                UpperCamelCase__      :       List[Any]	    =  [scores]
      elif self.framework == "tf":
           UpperCamelCase__      :       Optional[Any]	    =  stable_softmax(SCREAMING_SNAKE_CASE							,       axis=-1						)
           UpperCamelCase__      :       Optional[int]	    =  probs.numpy().tolist()
      else:
           raise ValueError(F'Unsupported framework: {self.framework}'						)

      UpperCamelCase__      :       Optional[int]	    =  [
          {"score": score, "label": candidate_label}
          for score, candidate_label in sorted(zip(SCREAMING_SNAKE_CASE							,       SCREAMING_SNAKE_CASE						)							,       key=lambda SCREAMING_SNAKE_CASE						: -x[0]						)
      ]
      return result