Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Default mask targets are not used when creating new segmentation annotation tasks #4976

Open
1 of 3 tasks
geke-mir opened this issue Oct 23, 2024 · 2 comments
Open
1 of 3 tasks
Labels
bug Bug fixes

Comments

@geke-mir
Copy link
Contributor

Describe the problem

The documentation states that datasets can have dataset.default_mask_targets or dataset.mask_targets here:

https://docs.voxel51.com/user_guide/using_datasets.html#storing-mask-targets

When creating a new segmentation task with FiftyOne without specifying mask_targets, classes 0-255 appear on CVAT. I doubt this default behavior is intuitive for users and perhaps this should work like annotating classifications, where users must specify classes or the annotation run crashes.

dataset.take(2).annotate("masks8", label_field="asdf", label_type="segmentation")

Code to reproduce issue

In [5]: from fiftyone import zoo

In [6]: dataset = zoo.load_zoo_dataset("quickstart")
Dataset already downloaded
Loading 'quickstart'
 100% |█████████████████████████████████████████████████████████████████████████████████████████████| 200/200 [1.6s elapsed, 0s remaining, 122.7 samples/s]         
Dataset 'quickstart' created

In [7]: dataset.default_mask_targets
Out[7]: {}

In [8]: dataset.take(2).annotate("jobbyjob", label_field="asdf", label_type="segmentation")

Computing metadata...
 100% |█████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [12.5ms elapsed, 0s remaining, 160.1 samples/s] 
Uploading samples to CVAT...
Out[8]: <fiftyone.utils.cvat.CVATAnnotationResults at 0x7e5936062090>

image

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 22.04): Ubuntu 22.04.4 LTS
  • Python version (python --version): 3.11.8
  • FiftyOne version (fiftyone --version): 0.25.1
  • FiftyOne installed from (pip or source): source

Other info/logs

The following diff seems to resolve the problem, but thought I'd open the issue first as this is more of a API/information flow change than a bug perhaps...

diff --git a/fiftyone/utils/annotations.py b/fiftyone/utils/annotations.py
index 9639da8d0..430af375a 100644
--- a/fiftyone/utils/annotations.py
+++ b/fiftyone/utils/annotations.py
@@ -844,10 +844,14 @@ def _parse_classes_dict(
 def _get_mask_targets(samples, mask_targets, label_field, label_info):
     if "mask_targets" in label_info:
         mask_targets = label_info["mask_targets"]
-
+    
+    # Check if we have defined a default mask target for the dataset
     if mask_targets is None:
-        mask_targets = {i: str(i) for i in range(1, 256)}
-        mask_targets[0] = "background"
+        if samples.default_mask_targets is not None:
+            mask_targets = samples.default_mask_targets
+        else:
+            mask_targets = {i: str(i) for i in range(1, 256)}
+            mask_targets[0] = "background"
 
     classes = [c for v, c in mask_targets.items() if v != 0]

Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another
member of your organization be willing to contribute a fix for this bug to the
FiftyOne codebase?

  • Yes. I can contribute a fix for this bug independently
  • Yes. I would be willing to contribute a fix for this bug with guidance
    from the FiftyOne community
  • No. I cannot contribute a bug fix at this time
@geke-mir geke-mir added the bug Bug fixes label Oct 23, 2024
@brimoor
Copy link
Contributor

brimoor commented Oct 24, 2024

Hi @geke-mir 👋

I agree that it would be consistent with how the classes argument works if we did the following for the mask_targets argument:

When annotating new segmentation fields:

The user is required to provide mask_targets argument to annotate()

When annotating existing segmentation fields:

If the user doesn't provide mask_targets to annotate(), then:

  • use mask targets from dataset.mask_targets[label_field] if they exist
  • else fallback to dataset.default_mask_targets if those exist
  • else fallback to the current default of:
mask_targets = {i: str(i) for i in range(1, 256)}
mask_targets[0] = "background"

A PR would be fantastic if you're open to contributing it! 😄

@geke-mir
Copy link
Contributor Author

Thanks, Brian!

#4990

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants