code: def convert_grounding_to_cls_scores(
      logits: Tensor, positive_maps: List[dict]
  ) -> Tensor:
      """Convert logits to class scores."""
      assert len(positive_maps) == logits.shape[0]  # batch size
  
      scores = torch.zeros(
          logits.shape[0], logits.shape[1], len(positive_maps[0])
      ).to(logits.device)
      if positive_maps is not None:
          if all(x == positive_maps[0] for x in positive_maps):
              # only need to compute once
              positive_map = positive_maps[0]
              for label_j in positive_map:
                  scores[:, :, label_j - 1] = logits[
                      :, :, torch.LongTensor(positive_map[label_j])
                  ].mean(-1)
          else:
              for i, positive_map in enumerate(positive_maps):
                  for label_j in positive_map:
                      scores[i, :, label_j - 1] = logits[
                          i, :, torch.LongTensor(positive_map[label_j])
                      ].mean(-1)
      return scores
  
imports: import copy
  import math
  from typing import Callable, List, Optional, Sequence, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Scale
  from mmcv.ops.modulated_deform_conv import ModulatedDeformConv2d
  from mmengine.config import ConfigDict
  from mmengine.model import BaseModel
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import cat_boxes
  from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
  from ..utils import BertEncoderLayer, VLFuse, filter_scores_and_topk, permute_and_flatten, select_single_mlvl, unpack_gt_instances
  from ..utils.vlfuse_helper import MAX_CLAMP_VALUE
  from .atss_head import ATSSHead
label_desc: Use image node_id 1 for calling a global function with example usage: convert_grounding_to_cls_scores(logits, positive_maps) and returns: scores