code: def center_of_mass(masks: Tensor, eps: float = 1e-7) -> Tensor:
      """Compute the masks center of mass.
  
      Args:
          masks: Mask tensor, has shape (num_masks, H, W).
          eps: a small number to avoid normalizer to be zero.
              Defaults to 1e-7.
      Returns:
          Tensor: The masks center of mass. Has shape (num_masks, 2).
      """
      n, h, w = masks.shape
      grid_h = torch.arange(h, device=masks.device)[:, None]
      grid_w = torch.arange(w, device=masks.device)
      normalizer = masks.sum(dim=(1, 2)).float().clamp(min=eps)
      center_y = (masks * grid_h).sum(dim=(1, 2)) / normalizer
      center_x = (masks * grid_w).sum(dim=(1, 2)) / normalizer
      center = torch.cat([center_x[:, None], center_y[:, None]], dim=1)
      return center
  
file_path: mmdetection/mmdet/models/task_modules/assigners/dynamic_soft_label_assigner.py
imports: from typing import Optional, Tuple
  import torch
  import torch.nn.functional
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import TASK_UTILS
  from mmdet.structures.bbox import BaseBoxes
  from mmdet.utils import ConfigType
  from .assign_result import AssignResult
  from .base_assigner import BaseAssigner
label_desc: Use image node_id 1 for calling a global function with example usage: center_of_mass(masks, eps) and returns: center