code: def segmentation_to_mask(polys, height, width):
      
      polys = [p.flatten().tolist() for p in polys]
      assert len(polys) > 0, "Polygons are empty!"
  
      import pycocotools.mask as cocomask
      rles = cocomask.frPyObjects(polys, height, width)
      rle = cocomask.merge(rles)
      return cocomask.decode(rle)
docs: Convert polygons to binary masks.
  
      Args:
          polys: a list of nx2 float array. Each array contains many (x, y) coordinates.
  
      Returns:
          a binary matrix of (height, width)