class_docstr: Defines the ExplainerManager for explaining an image-based model.
class_docstr_tok: ["Defines","the","ExplainerManager","for","explaining","an","image-based","model","."]
docstr: Creates an ExplainerManager object.
  
  :param model: The model to explain.
      A model that implements sklearn.predict or sklearn.predict_proba
      or function that accepts a 2d ndarray.
  :type model: object
  :param evaluation_examples: A matrix of feature vector
      examples (# examples x # features) on which to explain the
      model's output, with an additional label column.
  :type evaluation_examples: pandas.DataFrame
  :param target_column: The name of the label column.
  :type target_column: str
  :param task_type: The task to run.
  :type task_type: str
  :param classes: Class names as a list of strings.
      The order of the class names should match that of the model
      output. Only required if explaining classifier.
  :type classes: list
  :param image_mode: The mode to open the image in.
      See pillow documentation for all modes:
      https://pillow.readthedocs.io/en/stable/handbook/concepts.html
  :type image_mode: str
  :param max_evals: The maximum number of evaluations to run.
      Used by shap hierarchical image explainer.
      If not specified defaults to 100.
  :type max_evals: int
  :param num_masks: The number of masks to use for the
      DRISE image explainer for object detection.
      If not specified defaults to 50.
  :type num_masks: int
  :param mask_res: The resolution of the masks to use for the
      DRISE image explainer for object detection.
      If not specified defaults to 4.
  :type mask_res: int
  :param device: The device to run the model on.
      If not specified defaults to Device.AUTO.
  :type device: str
docstr_tok: ["Creates","an","ExplainerManager","object",".",":","param","model",":","The","model","to","explain",".","A","model","that","implements","sklearn.predict","or","sklearn.predict_proba","or","function","that","accepts","a","2d","ndarray",".",":","type","model",":","object",":","param","evaluation_examples",":","A","matrix","of","feature","vector","examples","(","#","examples","x","#","features",")","on","which","to","explain","the","model","'s","output",",","with","an","additional","label","column",".",":","type","evaluation_examples",":","pandas.DataFrame",":","param","target_column",":","The","name","of","the","label","column",".",":","type","target_column",":","str",":","param","task_type",":","The","task","to","run",".",":","type","task_type",":","str",":","param","classes",":","Class","names","as","a","list","of","strings",".","The","order","of","the","class","names","should","match","that","of","the","model","output",".","Only","required","if","explaining","classifier",".",":","type","classes",":","list",":","param","image_mode",":","The","mode","to","open","the","image","in",".","See","pillow","documentation","for","all","modes",":","https",":","\/\/pillow.readthedocs.io\/en\/stable\/handbook\/concepts.html",":","type","image_mode",":","str",":","param","max_evals",":","The","maximum","number","of","evaluations","to","run",".","Used","by","shap","hierarchical","image","explainer",".","If","not","specified","defaults","to","100.",":","type","max_evals",":","int",":","param","num_masks",":","The","number","of","masks","to","use","for","the","DRISE","image","explainer","for","object","detection",".","If","not","specified","defaults","to","50.",":","type","num_masks",":","int",":","param","mask_res",":","The","resolution","of","the","masks","to","use","for","the","DRISE","image","explainer","for","object","detection",".","If","not","specified","defaults","to","4.",":","type","mask_res",":","int",":","param","device",":","The","device","to","run","the","model","on",".","If","not","specified","defaults","to","Device.AUTO",".",":","type","device",":","str"]
code: def __init__(
      self,
      model: Any,
      evaluation_examples: pd.DataFrame,
      target_column: str,
      task_type: str,
      classes: Optional[List] = None,
      image_mode: str = None,
      max_evals: Optional[int] = DEFAULT_MAX_EVALS,
      num_masks: Optional[int] = DEFAULT_NUM_MASKS,
      mask_res: Optional[int] = DEFAULT_MASK_RES,
      device: Optional[str] = Device.AUTO.value,
  ):
      """Creates an ExplainerManager object.
  
      :param model: The model to explain.
          A model that implements sklearn.predict or sklearn.predict_proba
          or function that accepts a 2d ndarray.
      :type model: object
      :param evaluation_examples: A matrix of feature vector
          examples (# examples x # features) on which to explain the
          model's output, with an additional label column.
      :type evaluation_examples: pandas.DataFrame
      :param target_column: The name of the label column.
      :type target_column: str
      :param task_type: The task to run.
      :type task_type: str
      :param classes: Class names as a list of strings.
          The order of the class names should match that of the model
          output. Only required if explaining classifier.
      :type classes: list
      :param image_mode: The mode to open the image in.
          See pillow documentation for all modes:
          https://pillow.readthedocs.io/en/stable/handbook/concepts.html
      :type image_mode: str
      :param max_evals: The maximum number of evaluations to run.
          Used by shap hierarchical image explainer.
          If not specified defaults to 100.
      :type max_evals: int
      :param num_masks: The number of masks to use for the
          DRISE image explainer for object detection.
          If not specified defaults to 50.
      :type num_masks: int
      :param mask_res: The resolution of the masks to use for the
          DRISE image explainer for object detection.
          If not specified defaults to 4.
      :type mask_res: int
      :param device: The device to run the model on.
          If not specified defaults to Device.AUTO.
      :type device: str
      """
      self._image_mode = image_mode
      if task_type == ModelTask.OBJECT_DETECTION:
          if is_automl_image_model(model):
              try:
                  python_model = model._model._model_impl.python_model
                  automl_wrapper = python_model._model
                  inner_model = automl_wrapper._model
                  number_of_classes = automl_wrapper._number_of_classes
                  transforms = automl_wrapper.get_inference_transform()
                  self._model = PytorchDRiseWrapper(
                      inner_model,
                      number_of_classes,
                      device=device,
                      transforms=transforms,
                  )
              except Exception:
                  tb = traceback.format_exc()
                  warnings.warn(
                      (
                          "Could not extract inner automl model."
                          + "Explanation may take longer to compute."
                          + "Inner exception: {}"
                      ).format(tb),
                      UserWarning,
                  )
                  self._model = MLflowDRiseWrapper(
                      model._model, classes
                  )
          else:
              self._model = PytorchDRiseWrapper(
                  model._model, len(classes), device=device
              )
      else:
          self._model = model
      self._target_column = target_column
      if not isinstance(target_column, list):
          target_column = [target_column]
      self._evaluation_examples = evaluation_examples.drop(
          columns=target_column
      )
      self._is_run = False
      self._is_added = False
      self._features = list(self._evaluation_examples.columns)
      self._classes = classes
      self._explanation = None
      self._task_type = task_type
      self._max_evals = max_evals
      self._num_masks = num_masks
      self._mask_res = mask_res
      self._device = device
  
imports: import base64
  import io
  import json
  import pickle
  import traceback
  import warnings
  from pathlib import Path
  from typing import Any, List, Optional
  import cv2
  import matplotlib.pyplot
  import numpy
  import pandas
  import shap
  from ml_wrappers import wrap_model
  from ml_wrappers.common.constants import Device
  from ml_wrappers.model.image_model_wrapper import MLflowDRiseWrapper, PytorchDRiseWrapper
  from PIL import Image, ImageDraw, ImageFont
  from shap.plots import colors
  from shap.utils._legacy import kmeans
  from vision_explanation_methods.DRISE_runner import get_drise_saliency_map
  from responsibleai._interfaces import ModelExplanationData
  from responsibleai._internal.constants import ExplainerManagerKeys
  from responsibleai._internal.constants import ListProperties, ManagerNames, Metadata
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from responsibleai.exceptions import UserConfigValidationException
  from responsibleai.managers.base_manager import BaseManager
  from responsibleai_vision.common.constants import CommonTags, ExplainabilityDefaults, ExplainabilityLiterals, MLFlowSchemaLiterals, ModelTask, XAIPredictionLiterals
  from responsibleai_vision.utils.image_reader import get_base64_string_from_path, get_image_from_path, is_automl_image_model
label_desc: Use image node_id 1 to create a new ExplainerManager object from inherited base classes: BaseManager with example: obj = ExplainerManager(model, evaluation_examples, target_column, task_type, classes, image_mode, max_evals, num_masks, mask_res, device)