Anakin
Anakin

Reputation: 2010

Class-wise segmentation labels don't appear in FiftyOne dataset

I have a custom semantic segmentation dataset consisting of RGB images and corresponding RGB segmentation label images, where each unique RGB colour represents a class. I have managed to load this dataset into FiftyOne. I want to see the class information in the UI.

My sample minimum code is as follows:

import os
import fiftyone as fo

# Create a new FiftyOne dataset
dataset = fo.Dataset(name="custom_segmentation")
dataset.add_group_field("group")

# Dict corresponding hex colours to class
mask_targets = {'#87e7b0': 'Sky', '#c7b2de': 'Ceiling', '#ffd1d1': 'Solid'} # trimmed example
 
# Set the mask targets on the dataset
dataset.mask_targets = {"segmentation": mask_targets}

samples = []

# Loop over all images
for img_file in os.listdir(img_dir):
    img_file_path = os.path.join(img_dir, img_file)
    mask_file_path = os.path.join(img_dir, "sub", os.path.splitext(img_file)[0]+"_LABEL"+os.path.splitext(img_file)[1])

    # Create an image sample
    group = fo.Group()
    sample = fo.Sample(filepath=img_file_path,
                       ground_truth_mask=fo.Segmentation(mask_path=mask_file_path),
                       group=group.element("original"))
    sample["segmentation"] = fo.Segmentation(mask_path=mask_file_path)

    # Add sample to the list
    samples.append(sample)

# Add the samples to the dataset
dataset.add_samples(samples)

# Make the dataset persistent
dataset.persistent = True

# Save the dataset
dataset.save()

# Launch the app
session = fo.launch_app(dataset)
session.wait()

When I load it in the UI, I can see the original RGB image, and when the ground_truth_mask is enabled I see the label RGB image superimposed on the original image. But the segmentation field does not show the class information, I can just see the original image. Naturally, it doesn't show the class information as well.

I have confirmed that the filepath is correct and that the hex values for corresponding RGB values in the label image are correct as well. I have also checked the documentation from FiftyOne, for example here.

Unfortunately, I can not show examples of the image visualization as it is a proprietary dataset.

What can I try to resolve this?

Upvotes: 0

Views: 168

Answers (0)

Related Questions