instanceSegmentationTrainingData
R2026bSyntax
Description
The instanceSegmentationTrainingData function converts
polygon ROI labels in a groundTruth object into a training‑ready
datastore that provides images, bounding boxes, class labels, and instance masks. You
can pass the output datastore directly to train Mask R-CNN and SOLOv2 networks using the
trainMaskRCNN and trainSOLOV2 functions
respectively.
The instanceSegmentationTrainingData function requires a
groundTruth object containing polygon ROI labels. You can
create the groundTruth object by exporting labels from the Image Labeler
or Video Labeler
apps, or by importing COCO JSON annotations using the groundTruthFromCOCO function.
creates a datastore of instance segmentation training data ds = instanceSegmentationTrainingData(gTruth)ds
from the ground truth object gTruth. The function converts
polygon annotations to binary instance masks, derives bounding boxes from polygon
extents, and returns the results into a training-ready datastore
ds. The function includes only images that contain at least
one annotated polygon instance in the returned datastore.
specifies options using one or more name-value arguments in addition to the input
argument in the previous syntax. For example, ds = instanceSegmentationTrainingData(gTruth,Name=Value)SamplingFactor=5
extracts every fifth frame from video-based ground truth sources.
[
also returns an attribute datastore ds,arrds] = instanceSegmentationTrainingData(___)arrds containing
per-instance attributes and sublabels associated with the polygon labels. Use this
syntax when your ground truth includes attribute or sublabel definitions, such as
occlusion level or object color.
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Tips
The function writes output files to
<WriteLocation>/instanceSegTrainingData/withimages/andmasks/subfolders. Repeated calls automatically createinstanceSegTrainingData_1,instanceSegTrainingData_2, and so on — previous results are never overwritten.The function skips images that contain no annotated polygon instances. If all images in the
groundTruthare not annotated, the function throws an error.When you specify
gTruthas an array, all elements must have the same polygon label names. If the label definitions do not match, the function throws a validation error.For training functions that require a different column order than
{image, boxes, labels, masks}, extract the underlying datastores fromdsusingds.UnderlyingDatastoresand recombine them withcombine.ds.UnderlyingDatastores{1}—imageDatastorecontaining image files.ds.UnderlyingDatastores{2}—boxLabelDatastorecontaining bounding boxes and labels.ds.UnderlyingDatastores{3}—fileDatastorecontaining binary instance mask MAT files.
For large data sets, set
UseParallelto"auto"or"on"to parallelize mask generation across workers.
Extended Capabilities
Version History
Introduced in R2026b

