2021-06-20 22:00:16 +00:00
|
|
|
---
|
|
|
|
title: Masks
|
|
|
|
---
|
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
Masks are source data used in deep learning for image segmentation. Mask URIs are a property of a SingleFrame.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
ClearML applies the masks in one of two modes:
|
|
|
|
* [Pixel segmentation](#pixel-segmentation-masks) - Pixel RGB values are each mapped to segmentation labels.
|
|
|
|
* [Alpha channel](#alpha-channel-masks) - Pixel RGB values are interpreted as opacity levels.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
In the WebApp's [frame viewer](webapp/webapp_datasets_frames.md#frame-viewer), you can select how to apply a mask over
|
|
|
|
a frame.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
## Pixel Segmentation Masks
|
|
|
|
For pixel segmentation, mask RGB pixel values are mapped to labels.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
Mask-label mapping is defined at the dataset level, through the `mask_labels` property in a version's metadata.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
`mask_labels` is a list of dictionaries, where each dictionary includes the following keys:
|
|
|
|
* `value` - Mask's RGB pixel value
|
|
|
|
* `labels` - Label associated with the value.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
See how to manage dataset version mask labels pythonically [here](dataset.md#managing-version-mask-labels).
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
In the UI, you can view the mapping in a dataset version's [Metadata](webapp/webapp_datasets_versioning.md#metadata) tab.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2025-02-10 08:14:05 +00:00
|
|
|

|
|
|
|

|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-12-03 12:27:46 +00:00
|
|
|
When viewing a frame with a mask corresponding with the version's mask-label mapping, the UI arbitrarily assigns a color
|
2023-06-15 08:22:50 +00:00
|
|
|
to each label. The color assignment can be [customized](webapp/webapp_datasets_frames.md#labels).
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
For example:
|
|
|
|
* Original frame image:
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2025-02-10 08:14:05 +00:00
|
|
|

|
|
|
|

|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-12-03 12:27:46 +00:00
|
|
|
* Frame image with the semantic segmentation mask enabled. Labels are applied according to the dataset version's
|
2023-04-16 07:10:30 +00:00
|
|
|
mask-label mapping:
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2025-02-10 08:14:05 +00:00
|
|
|

|
|
|
|

|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
The frame's sources array contains a masks list of dictionaries that looks something like this:
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
```editorconfig
|
2021-06-20 22:00:16 +00:00
|
|
|
{
|
2023-04-16 07:10:30 +00:00
|
|
|
"id": "<framegroup_id>",
|
2023-06-15 08:22:50 +00:00
|
|
|
"timestamp": "<timestamp>",
|
2023-04-16 07:10:30 +00:00
|
|
|
"context_id": "car_1",
|
|
|
|
"sources": [
|
|
|
|
{
|
|
|
|
"id": "<source_id>",
|
|
|
|
"content_type": "<type>",
|
|
|
|
"uri": "<image_uri>",
|
|
|
|
"timestamp": 1234567889,
|
|
|
|
...
|
|
|
|
"masks": [
|
|
|
|
{
|
|
|
|
"id": "<mask_id>",
|
|
|
|
"content_type": "video/mp4",
|
|
|
|
"uri": "<mask_uri>",
|
|
|
|
"timestamp": 123456789
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2021-06-20 22:00:16 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-12-03 12:27:46 +00:00
|
|
|
The masks dictionary includes the frame's masks' URIs and IDs.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
## Alpha Channel Masks
|
|
|
|
For alpha channel, mask RGB pixel values are interpreted as opacity values so that when the mask is applied, only the
|
|
|
|
desired sections of the source are visible.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
For example:
|
|
|
|
* Original frame:
|
|
|
|
|
2025-02-10 08:14:05 +00:00
|
|
|

|
|
|
|

|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
* Same frame with an alpha channel mask, emphasizing the troll doll:
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2025-02-10 08:14:05 +00:00
|
|
|

|
|
|
|

|
2021-06-20 22:00:16 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
|
|
|
|
The frame's sources array contains a masks list of dictionaries that looks something like this:
|
|
|
|
|
|
|
|
```editorconfig
|
|
|
|
{
|
|
|
|
"sources" : [
|
|
|
|
{
|
|
|
|
"id" : "321"
|
|
|
|
"uri" : "https://i.ibb.co/bs7R9k6/troll.png"
|
|
|
|
"masks" : [
|
|
|
|
{
|
|
|
|
"id" : "troll",
|
|
|
|
"uri" : "https://i.ibb.co/TmJ3mvT/troll-alpha.png"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
"timestamp" : 0
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2021-06-20 22:00:16 +00:00
|
|
|
```
|
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
Note that for alpha channel masks, no labels are used.
|
2021-06-20 22:00:16 +00:00
|
|
|
|
2021-10-21 08:42:38 +00:00
|
|
|
## Usage
|
2023-04-16 07:10:30 +00:00
|
|
|
### Register Frames with a Masks
|
|
|
|
To register frames with a mask, create a frame and specify the frame's mask file's URI.
|
|
|
|
|
|
|
|
```python
|
|
|
|
# create dataset version
|
|
|
|
version = DatasetVersion.create_version(
|
|
|
|
dataset_name="Example",
|
|
|
|
version_name="Registering frame with mask"
|
|
|
|
)
|
|
|
|
|
|
|
|
# create frame with mask
|
|
|
|
frame = SingleFrame(
|
|
|
|
source='https://s3.amazonaws.com/allegro-datasets/cityscapes/leftImg8bit_trainvaltest/leftImg8bit/val/frankfurt/frankfurt_000000_000294_leftImg8bit.png',
|
|
|
|
mask_source='https://s3.amazonaws.com/allegro-datasets/cityscapes/gtFine_trainvaltest/gtFine/val/frankfurt/frankfurt_000000_000294_gtFine_labelIds.png'
|
|
|
|
)
|
2021-10-21 08:42:38 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
# add frame to version
|
|
|
|
version.add_frames([frame])
|
|
|
|
```
|
2021-10-21 08:42:38 +00:00
|
|
|
|
2023-04-16 07:10:30 +00:00
|
|
|
To use the mask for pixel segmentation, define the pixel-label mapping for the DatasetVersion:
|
2021-10-21 08:42:38 +00:00
|
|
|
|
|
|
|
```python
|
2023-04-16 07:10:30 +00:00
|
|
|
version.set_masks_labels(
|
|
|
|
{(0,0,0): ["background"], (1,1,1): ["person", "sitting"], (2,2,2): ["cat"]}
|
2021-12-14 13:12:30 +00:00
|
|
|
)
|
2021-10-21 08:42:38 +00:00
|
|
|
```
|
|
|
|
|
2023-12-03 12:27:46 +00:00
|
|
|
The relevant label is applied to all masks in the version according to the version's mask-label mapping dictionary.
|
2023-04-16 07:10:30 +00:00
|
|
|
|
|
|
|
### Registering Frames with Multiple Masks
|
2023-12-03 12:27:46 +00:00
|
|
|
Frames can contain multiple masks. To add multiple masks, use the SingleFrame's `masks_source` property. Input one of
|
2023-04-16 07:10:30 +00:00
|
|
|
the following:
|
|
|
|
* A dictionary with mask string ID keys and mask URI values
|
2023-08-01 14:05:53 +00:00
|
|
|
* A list of mask URIs. Number IDs are automatically assigned to the masks ("00", "01", etc.)
|
2023-04-16 07:10:30 +00:00
|
|
|
|
|
|
|
```python
|
|
|
|
frame = SingleFrame(source='https://s3.amazonaws.com/allegro-datasets/cityscapes/leftImg8bit_trainvaltest/leftImg8bit/val/frankfurt/frankfurt_000000_000294_leftImg8bit.png',)
|
|
|
|
|
|
|
|
# add multiple masks
|
|
|
|
# with dictionary
|
|
|
|
frame.masks_source={"ID 1 ": "<mask_URI_1>", "ID 2": "<mask_URI_2>"}
|
|
|
|
# with list
|
|
|
|
frame.masks_source=[ "<mask_URI_1>", "<mask_URI_2>"]
|
|
|
|
```
|
|
|
|
|