code: def draw_mask(im, np_boxes, np_masks, labels, threshold=0.5):
      """
      Args:
          im (PIL.Image.Image): PIL image
          np_boxes (np.ndarray): shape:[N,6], N: number of box,
              matix element:[class, score, x_min, y_min, x_max, y_max]
          np_masks (np.ndarray): shape:[N, im_h, im_w]
          labels (list): labels:['class1', ..., 'classn']
          threshold (float): threshold of mask
      Returns:
          im (PIL.Image.Image): visualized image
      """
      color_list = get_color_map_list(len(labels))
      w_ratio = 0.4
      alpha = 0.7
      im = np.array(im).astype("float32")
      clsid2color = {}
      expect_boxes = (np_boxes[:, 1] > threshold) & (
          np_boxes[:, 0] > -1
      )
      np_boxes = np_boxes[expect_boxes, :]
      np_masks = np_masks[expect_boxes, :, :]
      im_h, im_w = im.shape[:2]
      np_masks = np_masks[:, :im_h, :im_w]
      for i in range(len(np_masks)):
          clsid, score = int(np_boxes[i][0]), np_boxes[i][1]
          mask = np_masks[i]
          if clsid not in clsid2color:
              clsid2color[clsid] = color_list[clsid]
          color_mask = clsid2color[clsid]
          for c in range(3):
              color_mask[c] = (
                  color_mask[c] * (1 - w_ratio) + w_ratio * 255
              )
          idx = np.nonzero(mask)
          color_mask = np.array(color_mask)
          im[idx[0], idx[1], :] *= 1.0 - alpha
          im[idx[0], idx[1], :] += alpha * color_mask
      return Image.fromarray(im.astype("uint8"))
  
imports: from __future__ import division
  import os
  import cv2
  import math
  import numpy
  import PIL
  from PIL import Image, ImageDraw, ImageFile
label_desc: Use image node_id 4 for calling a global function with example usage: draw_mask(im, np_boxes, np_masks, labels, threshold) and returns: Image