class_docstr: Defines the top-level RAIVisionInsights API.
  
  Use RAIVisionInsights to assess vision machine learning models in a
  single API.
class_docstr_tok: ["Defines","the","top-level","RAIVisionInsights","API",".","Use","RAIVisionInsights","to","assess","vision","machine","learning","models","in","a","single","API","."]
docstr: Creates an RAIVisionInsights object.
  
  :param model: The model to compute RAI insights for.
      A model that implements sklearn.predict or sklearn.predict_proba
      or function that accepts a 2d ndarray.
  :type model: object
  :param test: The test dataframe including the label column.
  :type test: pd.DataFrame
  :param target_column: The name of the label column or list of columns.
      This is a list of columns for multilabel models.
  :type target_column:  str or list[str]
  :param task_type: The task to run.
  :type task_type: str
  :param classes: The class labels in the dataset.
  :type classes: numpy.ndarray
  :param serializer: Picklable custom serializer with save and load
      methods for custom model serialization.
      The save method writes the model to file given a parent directory.
      The load method returns the deserialized model from the same
      parent directory.
  :type serializer: object
  :param maximum_rows_for_test: Limit on size of test data
      (for performance reasons)
  :type maximum_rows_for_test: int
  :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 test_data_path: The path to the test data.
  :type test_data_path: str
  :param transformations: The transformations to apply to the image.
      This must be a callable or a string column name with
      transformed images.
  :type transformations: object
  :param image_downloader: The image downloader to use to download
      images from a URL.
  :type image_downloader: object
  :param feature_metadata: Feature metadata for the dataset
      to identify different kinds of features.
  :type feature_metadata: Optional[FeatureMetadata]
  :param image_width: The width to resize the image to.
      The size is in inches. Note larger resolutions in
      dashboard can cause slowness and memory errors.
      If not specified does not resize images.
  :type image_width: float
  :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","RAIVisionInsights","object",".",":","param","model",":","The","model","to","compute","RAI","insights","for",".","A","model","that","implements","sklearn.predict","or","sklearn.predict_proba","or","function","that","accepts","a","2d","ndarray",".",":","type","model",":","object",":","param","test",":","The","test","dataframe","including","the","label","column",".",":","type","test",":","pd.DataFrame",":","param","target_column",":","The","name","of","the","label","column","or","list","of","columns",".","This","is","a","list","of","columns","for","multilabel","models",".",":","type","target_column",":","str","or","list","[","str","]",":","param","task_type",":","The","task","to","run",".",":","type","task_type",":","str",":","param","classes",":","The","class","labels","in","the","dataset",".",":","type","classes",":","numpy.ndarray",":","param","serializer",":","Picklable","custom","serializer","with","save","and","load","methods","for","custom","model","serialization",".","The","save","method","writes","the","model","to","file","given","a","parent","directory",".","The","load","method","returns","the","deserialized","model","from","the","same","parent","directory",".",":","type","serializer",":","object",":","param","maximum_rows_for_test",":","Limit","on","size","of","test","data","(","for","performance","reasons",")",":","type","maximum_rows_for_test",":","int",":","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","test_data_path",":","The","path","to","the","test","data",".",":","type","test_data_path",":","str",":","param","transformations",":","The","transformations","to","apply","to","the","image",".","This","must","be","a","callable","or","a","string","column","name","with","transformed","images",".",":","type","transformations",":","object",":","param","image_downloader",":","The","image","downloader","to","use","to","download","images","from","a","URL",".",":","type","image_downloader",":","object",":","param","feature_metadata",":","Feature","metadata","for","the","dataset","to","identify","different","kinds","of","features",".",":","type","feature_metadata",":","Optional","[","FeatureMetadata","]",":","param","image_width",":","The","width","to","resize","the","image","to",".","The","size","is","in","inches",".","Note","larger","resolutions","in","dashboard","can","cause","slowness","and","memory","errors",".","If","not","specified","does","not","resize","images",".",":","type","image_width",":","float",":","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,
      test: pd.DataFrame,
      target_column: str,
      task_type: str,
      classes: Optional[np.ndarray] = None,
      serializer: Optional[Any] = None,
      maximum_rows_for_test: int = 5000,
      image_mode: str = ImageModes.RGB,
      test_data_path: Optional[str] = None,
      transformations: Optional[Any] = None,
      image_downloader: Optional[Any] = None,
      feature_metadata: Optional[FeatureMetadata] = None,
      image_width: Optional[float] = 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 RAIVisionInsights object.
  
      :param model: The model to compute RAI insights for.
          A model that implements sklearn.predict or sklearn.predict_proba
          or function that accepts a 2d ndarray.
      :type model: object
      :param test: The test dataframe including the label column.
      :type test: pd.DataFrame
      :param target_column: The name of the label column or list of columns.
          This is a list of columns for multilabel models.
      :type target_column:  str or list[str]
      :param task_type: The task to run.
      :type task_type: str
      :param classes: The class labels in the dataset.
      :type classes: numpy.ndarray
      :param serializer: Picklable custom serializer with save and load
          methods for custom model serialization.
          The save method writes the model to file given a parent directory.
          The load method returns the deserialized model from the same
          parent directory.
      :type serializer: object
      :param maximum_rows_for_test: Limit on size of test data
          (for performance reasons)
      :type maximum_rows_for_test: int
      :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 test_data_path: The path to the test data.
      :type test_data_path: str
      :param transformations: The transformations to apply to the image.
          This must be a callable or a string column name with
          transformed images.
      :type transformations: object
      :param image_downloader: The image downloader to use to download
          images from a URL.
      :type image_downloader: object
      :param feature_metadata: Feature metadata for the dataset
          to identify different kinds of features.
      :type feature_metadata: Optional[FeatureMetadata]
      :param image_width: The width to resize the image to.
          The size is in inches. Note larger resolutions in
          dashboard can cause slowness and memory errors.
          If not specified does not resize images.
      :type image_width: float
      :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
      """
      # drop index as this can cause issues later like when copying
      # target column below from test dataset to _ext_test_df
      test = test.reset_index(drop=True)
      if feature_metadata is None:
          # initialize to avoid having to keep checking if it is None
          feature_metadata = FeatureMetadata()
      self._feature_metadata = feature_metadata
      self.image_mode = image_mode
      self.image_width = image_width
      if max_evals is None:
          max_evals = DEFAULT_MAX_EVALS
      elif max_evals < 1:
          raise ValueError("max_evals must be greater than 0")
      if num_masks is None:
          num_masks = DEFAULT_NUM_MASKS
      elif num_masks < 1:
          raise ValueError("num_masks must be greater than 0")
      if mask_res is None:
          mask_res = DEFAULT_MASK_RES
      elif mask_res < 1:
          raise ValueError("mask_res must be greater than 0")
      if device is None:
          device = Device.AUTO.value
      self.max_evals = max_evals
      self.num_masks = num_masks
      self.mask_res = mask_res
      self.device = device
      self.test_mltable_path = test_data_path
      self._transformations = transformations
      self._image_downloader = image_downloader
      sample = test.iloc[0:2]
      sample = get_images(
          sample, self.image_mode, self._transformations
      )
      self._wrapped_model = wrap_model(
          model, sample, task_type, classes=classes, device=device
      )
  
      # adding this field to use in _get_single_image and _save_predictions
      self._task_type = task_type
  
      self.automl_image_model = is_automl_image_model(
          self._wrapped_model
      )
  
      self._validate_rai_insights_input_parameters(
          model=self._wrapped_model,
          test=test,
          target_column=target_column,
          task_type=task_type,
          classes=classes,
          serializer=serializer,
          maximum_rows_for_test=maximum_rows_for_test,
      )
      self._classes = RAIVisionInsights._get_classes(
          task_type=task_type,
          test=test,
          target_column=target_column,
          classes=classes,
      )
      self.predict_output = None
      if task_type == ModelTask.OBJECT_DETECTION:
          test = transform_object_detection_labels(
              test, target_column, self._classes
          )
      super(RAIVisionInsights, self).__init__(
          model, None, test, target_column, task_type, serializer
      )
  
      ext_test, ext_features = extract_features(
          self.test,
          self.target_column,
          self.image_mode,
          self._feature_metadata,
      )
      self._ext_test = ext_test
      self._ext_features = ext_features
  
      self._ext_test_df = pd.DataFrame(ext_test, columns=ext_features)
      self._ext_test_df[target_column] = test[target_column]
      self._initialize_managers()
  
imports: import base64
  import io
  import json
  import os
  import pickle
  import shutil
  import warnings
  from collections import defaultdict
  from enum import Enum
  from pathlib import Path
  from typing import Any, Optional
  import matplotlib.pyplot
  import numpy
  import pandas
  import torch
  from ml_wrappers import wrap_model
  from ml_wrappers.common.constants import Device
  from torchmetrics.detection.mean_ap import MeanAveragePrecision
  from vision_explanation_methods.error_labeling.error_labeling import ErrorLabeling, ErrorLabelType
  from erroranalysis._internal.cohort_filter import FilterDataWithCohortFilters
  from raiutils.data_processing import convert_to_list
  from raiutils.models.model_utils import SKLearn
  from responsibleai._interfaces import Dataset, RAIInsightsData
  from responsibleai._internal.constants import ManagerNames, Metadata, SerializationAttributes
  from responsibleai.exceptions import UserConfigValidationException
  from responsibleai.feature_metadata import FeatureMetadata
  from responsibleai.rai_insights.rai_base_insights import RAIBaseInsights
  from responsibleai.serialization_utilities import serialize_json_safe
  from responsibleai_vision.common.constants import CommonTags, ExplainabilityDefaults, ImageColumns, ImageModes, MLFlowSchemaLiterals, ModelTask
  from responsibleai_vision.managers.error_analysis_manager import ErrorAnalysisManager
  from responsibleai_vision.managers.explainer_manager import ExplainerManager
  from responsibleai_vision.utils.feature_extractors import extract_features
  from responsibleai_vision.utils.image_reader import get_base64_string_from_path, get_image_from_path, is_automl_image_model
  from responsibleai_vision.utils.image_utils import convert_images, get_images, transform_object_detection_labels
label_desc: Use image node_id 1 to create a new RAIVisionInsights object from inherited base classes: RAIBaseInsights with example: obj = RAIVisionInsights(model, test, target_column, task_type, classes, serializer, maximum_rows_for_test, image_mode, test_data_path, transformations, image_downloader, feature_metadata, image_width, max_evals, num_masks, mask_res, device)