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","."]
code: def compute_object_detection_metrics(
      self,
      selection_indexes,
      aggregate_method,
      class_name,
      iou_threshold,
      object_detection_cache,
  ):
      dashboard_dataset = self.get_data().dataset
      true_y = dashboard_dataset.object_detection_true_y
      predicted_y = dashboard_dataset.object_detection_predicted_y
      if self.device == Device.AUTO.value:
          # currently only supports single GPU instance
          device = torch.device(
              "cuda:0" if torch.cuda.is_available() else "cpu"
          )
      else:
          device = torch.device(self.device)
      normalized_iou_threshold = [iou_threshold / 100.0]
      all_cohort_metrics = []
      all_cohort_classes = []
      for cohort_indices in selection_indexes:
          key = ",".join(
              [str(cid) for cid in cohort_indices]
              + [aggregate_method, class_name, str(iou_threshold)]
          )
          if key in object_detection_cache:
              all_cohort_metrics.append(object_detection_cache[key])
              all_cohort_classes.append([class_name])
              continue
  
          metric_OD = MeanAveragePrecision(
              average=aggregate_method.lower(),
              class_metrics=True,
              iou_thresholds=normalized_iou_threshold,
          ).to(device)
          true_y_cohort = [
              true_y[cohort_index] for cohort_index in cohort_indices
          ]
          predicted_y_cohort = [
              predicted_y[cohort_index]
              for cohort_index in cohort_indices
          ]
  
          pred_boxes, pred_labels, pred_scores = [], [], []
          for pred_image in predicted_y_cohort:
              for pred_object in pred_image:
                  pred_labels.append(int(pred_object[0]))
                  pred_boxes.append(pred_object[1:5])
                  pred_scores.append(pred_object[-1])
  
          gt_boxes, gt_labels = [], []
          for gt_image in true_y_cohort:
              for gt_object in gt_image:
                  gt_labels.append(int(gt_object[0]))
                  gt_boxes.append(gt_object[1:5])
          # creating the list of dictionaries for pred and gt
          cohort_pred = [
              dict(
                  boxes=torch.tensor(pred_boxes).to(device),
                  scores=torch.tensor(pred_scores).to(device),
                  labels=torch.tensor(pred_labels).to(device),
              )
          ]
          cohort_gt = [
              dict(
                  boxes=torch.tensor(gt_boxes).to(device),
                  labels=torch.tensor(gt_labels).to(device),
              )
          ]
  
          # this is to find the class index given
          # that there might not all classes in the cohort to predict or gt
          classes = self._classes
          classes = list(classes)
          cohort_classes = list(
              set([classes[i - 1] for i in pred_labels + gt_labels])
          )
          cohort_classes.sort(key=lambda cname: classes.index(cname))
          # to catch if the class is not in the cohort
          if class_name not in cohort_classes:
              all_cohort_metrics.append([-1, -1, -1])
              all_cohort_classes.append([class_name])
          else:
              metric_OD.update(cohort_pred, cohort_gt)
              object_detection_values = metric_OD.compute()
              mAP = round(object_detection_values["map"].item(), 2)
              AP_tensor = object_detection_values[
                  "map_per_class"
              ].detach()
              AP_tensor = (
                  [AP_tensor.item()]
                  if AP_tensor.numel() == 1
                  else AP_tensor.tolist()
              )
              AR_tensor = object_detection_values[
                  "mar_100_per_class"
              ].detach()
              AR_tensor = (
                  [AR_tensor.item()]
                  if AR_tensor.numel() == 1
                  else AR_tensor.tolist()
              )
              APs = [round(value, 2) for value in AP_tensor]
              ARs = [round(value, 2) for value in AR_tensor]
  
              assert len(APs) == len(ARs) == len(cohort_classes)
  
              all_submetrics = [
                  [mAP, APs[i], ARs[i]] for i in range(len(APs))
              ]
              all_cohort_metrics.append(all_submetrics)
              all_cohort_classes.append(cohort_classes)
      return [all_cohort_metrics, all_cohort_classes]
  
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 29 for calling the RAIVisionInsights obj's underlying member method code with example usage: obj.compute_object_detection_metrics(selection_indexes, aggregate_method, class_name, iou_threshold, object_detection_cache) and returns: list