code: def generate_mask_target(
      gt_segms,
      rois,
      labels_int32,
      sampled_gt_inds,
      num_classes,
      resolution,
  ):
      mask_rois = []
      mask_rois_num = []
      tgt_masks = []
      tgt_classes = []
      mask_index = []
      tgt_weights = []
      for k in range(len(rois)):
          labels_per_im = labels_int32[k]
          # select rois labeled with foreground
          fg_inds = paddle.nonzero(
              paddle.logical_and(
                  labels_per_im != -1, labels_per_im != num_classes
              )
          )
          has_fg = True
          # generate fake roi if foreground is empty
          if fg_inds.numel() == 0:
              has_fg = False
              fg_inds = paddle.ones([1, 1], dtype="int64")
          inds_per_im = sampled_gt_inds[k]
          inds_per_im = paddle.gather(inds_per_im, fg_inds)
  
          rois_per_im = rois[k]
          fg_rois = paddle.gather(rois_per_im, fg_inds)
          # Copy the foreground roi to cpu
          # to generate mask target with ground-truth
          boxes = fg_rois.numpy()
          gt_segms_per_im = gt_segms[k]
  
          new_segm = []
          inds_per_im = inds_per_im.numpy()
          if len(gt_segms_per_im) > 0:
              for i in inds_per_im:
                  new_segm.append(gt_segms_per_im[i])
          fg_inds_new = fg_inds.reshape([-1]).numpy()
          results = []
          if len(gt_segms_per_im) > 0:
              for j in range(fg_inds_new.shape[0]):
                  results.append(
                      rasterize_polygons_within_box(
                          new_segm[j], boxes[j], resolution
                      )
                  )
          else:
              results.append(
                  paddle.ones([resolution, resolution], dtype="int32")
              )
  
          fg_classes = paddle.gather(labels_per_im, fg_inds)
          weight = paddle.ones([fg_rois.shape[0]], dtype="float32")
          if not has_fg:
              # now all sampled classes are background
              # which will cause error in loss calculation,
              # make fake classes with weight of 0.
              fg_classes = paddle.zeros([1], dtype="int32")
              weight = weight - 1
          tgt_mask = paddle.stack(results)
          tgt_mask.stop_gradient = True
          fg_rois.stop_gradient = True
  
          mask_index.append(fg_inds)
          mask_rois.append(fg_rois)
          mask_rois_num.append(paddle.shape(fg_rois)[0:1])
          tgt_classes.append(fg_classes)
          tgt_masks.append(tgt_mask)
          tgt_weights.append(weight)
  
      mask_index = paddle.concat(mask_index)
      mask_rois_num = paddle.concat(mask_rois_num)
      tgt_classes = paddle.concat(tgt_classes, axis=0)
      tgt_masks = paddle.concat(tgt_masks, axis=0)
      tgt_weights = paddle.concat(tgt_weights, axis=0)
  
      return (
          mask_rois,
          mask_rois_num,
          tgt_classes,
          tgt_masks,
          mask_index,
          tgt_weights,
      )
  
file_path: PaddleDetection/ppdet/modeling/proposal_generator/target.py
imports: import numpy
  import paddle
  from ..bbox_utils import bbox2delta, bbox_overlaps
label_desc: Use image node_id 8 for calling a global function with example usage: generate_mask_target(gt_segms, rois, labels_int32, sampled_gt_inds, num_classes, resolution) and returns: mask_rois,  mask_rois_num,  tgt_classes,  tgt_masks,  mask_index,  tgt_weights