code: def im_detect_mask(model, im_scale, boxes):
      """Infer instance segmentation masks. This function must be called after
      im_detect_bbox as it assumes that the Caffe2 workspace is already populated
      with the necessary blobs.
  
      Arguments:
          model (DetectionModelHelper): the detection model to use
          im_scales (list): image blob scales as returned by im_detect_bbox
          boxes (ndarray): R x 4 array of bounding box detections (e.g., as
              returned by im_detect_bbox)
  
      Returns:
          pred_masks (ndarray): R x K x M x M array of class specific soft masks
              output by the network (must be processed by segm_results to convert
              into hard masks in the original image coordinate space)
      """
      M = cfg.MRCNN.RESOLUTION
      if boxes.shape[0] == 0:
          pred_masks = np.zeros((0, M, M), np.float32)
          return pred_masks
  
      inputs = {"mask_rois": _get_rois_blob(boxes, im_scale)}
      # Add multi-level rois for FPN
      if cfg.FPN.MULTILEVEL_ROIS:
          _add_multilevel_rois_for_test(inputs, "mask_rois")
  
      for k, v in inputs.items():
          workspace.FeedBlob(core.ScopedName(k), v)
      workspace.RunNet(model.mask_net.Proto().name)
  
      # Fetch masks
      pred_masks = workspace.FetchBlob(
          core.ScopedName("mask_fcn_probs")
      ).squeeze()
  
      if cfg.MRCNN.CLS_SPECIFIC_MASK:
          pred_masks = pred_masks.reshape(
              [-1, cfg.MODEL.NUM_CLASSES, M, M]
          )
      else:
          pred_masks = pred_masks.reshape([-1, 1, M, M])
  
      return pred_masks
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from collections import defaultdict
  import cv2
  import logging
  import numpy
  from caffe2.python import core
  from caffe2.python import workspace
  import pycocotools.mask
  from detectron.core.config import cfg
  from detectron.utils.timer import Timer
  import detectron.core.test_retinanet
  import detectron.modeling.FPN
  import detectron.utils.blob
  import detectron.utils.boxes
  import detectron.utils.image
  import detectron.utils.keypoints
label_desc: Use image node_id 8 for calling a global function with example usage: im_detect_mask(model, im_scale, boxes) and returns: pred_masks, pred_masks