code: def draw_mask(
      im, np_boxes, np_masks, labels, resolution=14, 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, class_num, resolution, resolution]
          labels (list): labels:['class1', ..., 'classn']
          resolution (int): shape of a mask is:[resolution, resolution]
          threshold (float): threshold of mask
      Returns:
          im (PIL.Image.Image): visualized image
      """
      color_list = get_color_map_list(len(labels))
      scale = (resolution + 2.0) / resolution
      im_w, im_h = im.size
      w_ratio = 0.4
      alpha = 0.7
      im = np.array(im).astype("float32")
      rects = np_boxes[:, 2:]
      expand_rects = expand_boxes(rects, scale)
      expand_rects = expand_rects.astype(np.int32)
      clsid_scores = np_boxes[:, 0:2]
      padded_mask = np.zeros(
          (resolution + 2, resolution + 2), dtype=np.float32
      )
      clsid2color = {}
      for idx in range(len(np_boxes)):
          clsid, score = clsid_scores[idx].tolist()
          clsid = int(clsid)
          xmin, ymin, xmax, ymax = expand_rects[idx].tolist()
          w = xmax - xmin + 1
          h = ymax - ymin + 1
          w = np.maximum(w, 1)
          h = np.maximum(h, 1)
          padded_mask[1:-1, 1:-1] = np_masks[idx, int(clsid), :, :]
          resized_mask = cv2.resize(padded_mask, (w, h))
          resized_mask = np.array(
              resized_mask > threshold, dtype=np.uint8
          )
          x0 = min(max(xmin, 0), im_w)
          x1 = min(max(xmax + 1, 0), im_w)
          y0 = min(max(ymin, 0), im_h)
          y1 = min(max(ymax + 1, 0), im_h)
          im_mask = np.zeros((im_h, im_w), dtype=np.uint8)
          im_mask[y0:y1, x0:x1] = resized_mask[
              (y0 - ymin) : (y1 - ymin), (x0 - xmin) : (x1 - xmin)
          ]
          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(im_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"))
  
file_path: PaddleHub/modules/image/instance_segmentation/solov2/data_feed.py
imports: import base64
  import cv2
  import numpy
  from paddle.inference import Config
  from paddle.inference import create_predictor
  from paddle.inference import PrecisionType
  from PIL import Image
  from PIL import ImageDraw
label_desc: Use image node_id 5 for calling a global function with example usage: draw_mask(im, np_boxes, np_masks, labels, resolution, threshold) and returns: Image