code: def _segm_to_mask(self, segm, size):
      # Copied from pycocotools.coco.COCO.annToMask
      H, W = size
      if isinstance(segm, list):
          # polygon -- a single object might consist of multiple parts
          # we merge all parts into one mask rle code
          mask = np.zeros((H, W), dtype=np.uint8)
          mask = PIL.Image.fromarray(mask)
          for sgm in segm:
              xy = np.array(sgm).reshape((-1, 2))
              xy = [tuple(xy_i) for xy_i in xy]
              PIL.ImageDraw.Draw(mask).polygon(xy=xy, outline=1, fill=1)
          mask = np.asarray(mask)
      elif isinstance(segm["counts"], list):
          rle = coco_mask.frPyObjects(segm, H, W)
          mask = coco_mask.decode(rle)
      else:
          mask = coco_mask.decode(segm)
      return mask.astype(np.bool)
  
file_path: chainercv/chainercv/datasets/coco/coco_instances_base_dataset.py
imports: from collections import defaultdict
  import json
  import numpy
  import os
  import PIL.Image
  import PIL.ImageDraw
  from chainercv.chainer_experimental.datasets.sliceable import GetterDataset
  from chainercv.datasets.coco.coco_utils import get_coco
  from chainercv import utils
label_desc: Use image node_id 6 for calling the COCOInstancesBaseDataset obj's underlying member method code with example usage: obj._segm_to_mask(segm, size) and returns: mask