Instance segmentation models detect instances in an image and produce a binary mask for each of them, as well as their category.
Datasets follow this structure:
endpoint_url/bucket/
├── prefix/images/
├── prefix/instance_masks/
└── prefix/metadata.yaml
Dataset images are placed directly inside images/ (subdirectories are ignored).
The metadata file looks something like this:
task: instance segmentation
annotations: instance_masks/
categories: [cat1, cat2, cat3]
colors:
cat1: [255, 0, 0] # red
cat2: [0, 0, 255] # blue
cat3: [255, 255, 0] # yellow
The annotations field specifies the name of
the folder containing the ground truth annotations, which share the file name
with the image they are associated with (e.g. instance_masks/000.tif annotates images/000.jpg).
An annotation is a multi-page RGB TIFF file, each page being a binary mask using
one of 2 colors:
Here's an example of how to generate such images in Python:
import numpy as np
import tifffile
# generate 5 binary masks of size (100, 100) and their category colors
masks = np.random.randint(0, 2, size=(5, 1, 100, 100), dtype=np.uint8) # binary masks
CAT1, CAT2, CAT3 = [255, 0, 0], [0, 0, 255], [255, 255, 0] # red, blue, yellow
colors = np.array([CAT1, CAT3, CAT3, CAT2, CAT1], dtype=np.uint8).reshape((5, 3, 1, 1))
masks = masks * colors # shapes are broadcasted to (5, 3, 100, 100)
tifffile.imwrite("tmp.tiff", masks)