class_docstr: A mask point head use in PointRend.
  
  ``MaskPointHead`` use shared multi-layer perceptron (equivalent to
  nn.Conv1d) to predict the logit of input points. The fine-grained feature
  and coarse feature will be concatenate together for predication.
  
  Args:
      num_fcs (int): Number of fc layers in the head. Default: 3.
      in_channels (int): Number of input channels. Default: 256.
      fc_channels (int): Number of fc channels. Default: 256.
      num_classes (int): Number of classes for logits. Default: 80.
      class_agnostic (bool): Whether use class agnostic classification.
          If so, the output channels of logits will be 1. Default: False.
      coarse_pred_each_layer (bool): Whether concatenate coarse feature with
          the output of each fc layer. Default: True.
      conv_cfg (dict | None): Dictionary to construct and config conv layer.
          Default: dict(type='Conv1d'))
      norm_cfg (dict | None): Dictionary to construct and config norm layer.
          Default: None.
      loss_point (dict): Dictionary to construct and config loss layer of
          point head. Default: dict(type='CrossEntropyLoss', use_mask=True,
          loss_weight=1.0).
docstr: Get ``num_points`` most uncertain points with random points during
  train.
  
  Sample points in [0, 1] x [0, 1] coordinate space based on their
  uncertainty. The uncertainties are calculated for each point using
  '_get_uncertainty()' function that takes point's logit prediction as
  input.
  
  Args:
      mask_pred (Tensor): A tensor of shape (num_rois, num_classes,
          mask_height, mask_width) for class-specific or class-agnostic
          prediction.
      labels (list): The ground truth class for each instance.
      cfg (dict): Training config of point head.
  
  Returns:
      point_coords (Tensor): A tensor of shape (num_rois, num_points, 2)
          that contains the coordinates sampled points.
docstr_tok: ["Get","``","num_points","``","most","uncertain","points","with","random","points","during","train",".","Sample","points","in","[","0",",","1","]","x","[","0",",","1","]","coordinate","space","based","on","their","uncertainty",".","The","uncertainties","are","calculated","for","each","point","using","'_get_uncertainty","(",")","'","function","that","takes","point","'s","logit","prediction","as","input",".","Args",":","mask_pred","(","Tensor",")",":","A","tensor","of","shape","(","num_rois",",","num_classes",",","mask_height",",","mask_width",")","for","class-specific","or","class-agnostic","prediction",".","labels","(","list",")",":","The","ground","truth","class","for","each","instance",".","cfg","(","dict",")",":","Training","config","of","point","head",".","Returns",":","point_coords","(","Tensor",")",":","A","tensor","of","shape","(","num_rois",",","num_points",",","2",")","that","contains","the","coordinates","sampled","points","."]
code: def get_roi_rel_points_train(self, mask_pred, labels, cfg):
      """Get ``num_points`` most uncertain points with random points during
      train.
  
      Sample points in [0, 1] x [0, 1] coordinate space based on their
      uncertainty. The uncertainties are calculated for each point using
      '_get_uncertainty()' function that takes point's logit prediction as
      input.
  
      Args:
          mask_pred (Tensor): A tensor of shape (num_rois, num_classes,
              mask_height, mask_width) for class-specific or class-agnostic
              prediction.
          labels (list): The ground truth class for each instance.
          cfg (dict): Training config of point head.
  
      Returns:
          point_coords (Tensor): A tensor of shape (num_rois, num_points, 2)
              that contains the coordinates sampled points.
      """
      num_points = cfg.num_points
      oversample_ratio = cfg.oversample_ratio
      importance_sample_ratio = cfg.importance_sample_ratio
      assert oversample_ratio >= 1
      assert 0 <= importance_sample_ratio <= 1
      batch_size = mask_pred.shape[0]
      num_sampled = int(num_points * oversample_ratio)
      point_coords = torch.rand(
          batch_size, num_sampled, 2, device=mask_pred.device
      )
      point_logits = point_sample(mask_pred, point_coords)
      # It is crucial to calculate uncertainty based on the sampled
      # prediction value for the points. Calculating uncertainties of the
      # coarse predictions first and sampling them for points leads to
      # incorrect results.  To illustrate this: assume uncertainty func(
      # logits)=-abs(logits), a sampled point between two coarse
      # predictions with -1 and 1 logits has 0 logits, and therefore 0
      # uncertainty value. However, if we calculate uncertainties for the
      # coarse predictions first, both will have -1 uncertainty,
      # and sampled point will get -1 uncertainty.
      point_uncertainties = self._get_uncertainty(point_logits, labels)
      num_uncertain_points = int(importance_sample_ratio * num_points)
      num_random_points = num_points - num_uncertain_points
      idx = torch.topk(
          point_uncertainties[:, 0, :], k=num_uncertain_points, dim=1
      )[1]
      shift = num_sampled * torch.arange(
          batch_size, dtype=torch.long, device=mask_pred.device
      )
      idx += shift[:, None]
      point_coords = point_coords.view(-1, 2)[idx.view(-1), :].view(
          batch_size, num_uncertain_points, 2
      )
      if num_random_points > 0:
          rand_roi_coords = torch.rand(
              batch_size, num_random_points, 2, device=mask_pred.device
          )
          point_coords = torch.cat(
              (point_coords, rand_roi_coords), dim=1
          )
      return point_coords
  
file_path: insightface/detection/scrfd/mmdet/models/roi_heads/mask_heads/mask_point_head.py
imports: import torch
  import torch.nn
  from mmcv.cnn import ConvModule, normal_init
  from mmcv.ops import point_sample, rel_roi_point_to_rel_img_point
  from mmdet.models.builder import HEADS, build_loss
label_desc: Use image node_id 8 for calling the MaskPointHead obj's underlying member method code with example usage: obj.get_roi_rel_points_train(mask_pred, labels, cfg) and returns: point_coords