Overview

Build an instance segmentation dataset

Unofficial preview. Docsbook assembled this page from the public wkentaro/labelme README.md and examples/ directory. It is not affiliated with, endorsed by, or maintained by the Labelme project. The official documentation lives at labelme.io/docs.

Instance segmentation keeps objects apart. Three people standing together are three separate masks, not one person region. This is the examples/instance_segmentation workflow, and it is the only one that exports to both Pascal VOC and COCO.

Annotate the directory#

labelme data_annotated --labels labels.txt --validate-label exact \
  --config '{shape_color: {mode: auto, auto: {shift: -2}}}'

To let annotators mark occlusion and truncation while they draw, add per-label flags:

labelme data_annotated --labels labels.txt \
  --label-flags '{.*: [occluded, truncated], person: [male]}'

Labelme with each object outlined as its own polygon instance

Export to Pascal VOC#

./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt

Without --noobject, the script writes both the class outputs and the per-object ones:

Directory What it holds
JPEGImages The source images
SegmentationClass, SegmentationClassNpy Class masks, PNG and numpy
SegmentationClassVisualization Colourised class masks
SegmentationObject, SegmentationObjectNpy Per-instance masks, PNG and numpy
SegmentationObjectVisualization Colourised instance masks

The source image beside its class mask and its per-instance mask visualisation

The class and object visualisations are the check: if two touching objects share one colour in the object mask, they were annotated as one instance.

Export to COCO#

./labelme2coco.py data_annotated data_dataset_coco --labels labels.txt

This produces a data_dataset_coco/JPEGImages directory and a single data_dataset_coco/annotations.json. See export to COCO for what that file contains and how loaders expect it laid out.

Updated

Was this page helpful?