code: def compute_mean_average_precision(
      logits,
      labels,
      suffix="",
      suffix_separator="_",
      return_per_class_ap=False,
  ):
      """Computes mean average precision for multi-label classification.
  
      Args:
        logits: Numpy array of shape [num_examples, num_classes]
        labels: Numpy array of shape [num_examples, num_classes]
        suffix: Suffix to add to the summary
        suffix_separator: Separator before adding the suffix
        return_per_class_ap: If True, return results for each class in the summary.
  
      Returns:
        summary: Dictionary containing the mean average precision, and also the
          average precision per class.
      """
  
      assert (
          logits.shape == labels.shape
      ), "Logits and labels have different shapes"
      n_classes = logits.shape[1]
      average_precisions = []
      if suffix:
          suffix = suffix_separator + suffix
      summary = {}
  
      for i in range(n_classes):
          ave_precision = average_precision_score(
              labels[:, i], logits[:, i]
          )
          if np.isnan(ave_precision):
              logging.warning("AP for class %d is NaN", i)
  
          if return_per_class_ap:
              summary_key = f"per_class_average_precision_{i}{suffix}"
              summary[summary_key] = ave_precision
          average_precisions.append(ave_precision)
  
      mean_ap = np.nanmean(average_precisions)
      summary[f"mean_average_precision{suffix}"] = mean_ap
      logging.info("Mean AP is %0.3f", mean_ap)
  
      return summary
  
file_path: scenic/scenic/projects/vivit/evaluation_lib.py
imports: import os
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Union
  from absl import logging
  import flax
  from flax.metrics import tensorboard
  from flax.training import checkpoints
  import jax
  import jax.numpy
  import numpy
  from scenic.train_lib_deprecated import pretrain_utils
  from scenic.train_lib_deprecated import train_utils
  from sklearn.metrics import average_precision_score
  from tensorflow.io import gfile
label_desc: Use image node_id 2 for calling a global function with example usage: compute_mean_average_precision(logits, labels, suffix, suffix_separator, return_per_class_ap) and returns: summary