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

Use CVAT brush tool (aka mask shape) when annotating instance segmentation masks #5319

Merged
merged 6 commits into from
Jan 2, 2025

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Dec 26, 2024

Finalizes #4483

Change log

  • The CVAT integration now uses the brush tool (aka mask shape) to annotate instance segmentations when connected to CVAT Server >= v2.3

Tested by

# Tested with latest CVAT server to ensure brush tool works
export FIFTYONE_CVAT_URL=https://app.cvat.ai

# Tested with a <2.3 CVAT server to ensure backwards compatibility 
export FIFTYONE_CVAT_URL=http://localhost:8080
import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset(
    "coco-2017",
    split="validation",
    label_types="segmentations",
    label_field="instances",
    classes=["person"],
    max_samples=5,
    only_matching=True,
)

results = dataset.annotate(
    "test",
    label_field="instances",
    label_type="instances",
    launch_editor=True,
)

# Perform some edits in CVAT...

dataset.load_annotations("test")

session = fo.launch_app(dataset)

Summary by CodeRabbit

  • New Features
    • Introduced functionality for converting RLE format instance masks to binary image masks and vice versa.
    • Enhanced the CVATShape class to support instance masks in the conversion process.
    • Improved handling of shape types based on server version for instance segmentation in CVAT annotations.

NicDionne and others added 6 commits October 16, 2024 20:26
@brimoor brimoor added the feature Work on a feature request label Dec 26, 2024
@brimoor brimoor requested a review from ehofesmann December 26, 2024 23:51
Copy link
Contributor

coderabbitai bot commented Dec 26, 2024

Walkthrough

The pull request enhances the CVAT integration in FiftyOne by introducing a new HasCVATBinaryMask class that provides methods for converting between Run-Length Encoding (RLE) and binary image masks. The changes improve the handling of instance segmentation annotations by adding support for converting masks between different formats. The modifications extend the CVATShape and CVATBackend classes to support more flexible mask handling, particularly for different CVAT server versions.

Changes

File Change Summary
fiftyone/utils/cvat.py - Added HasCVATBinaryMask class with RLE conversion methods
- Updated CVATShape.to_instance() to support mask conversions
- Modified _create_detection_shapes() to handle different mask types

Possibly related issues

Possibly related PRs

Suggested labels

annotation

Suggested reviewers

  • ehofesmann

Poem

🐰 Masks and pixels dance with glee,
CVAT's secrets now set free!
RLE to binary, a magic spell,
Segmentation's tale we'll tell
With FiftyOne's clever art! 🎨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
fiftyone/utils/cvat.py (1)

1590-1614: Ensure robustness & unit testing for new RLE methods

The new HasCVATBinaryMask class establishes a solid foundation for encoding and decoding RLE instance masks. However, consider these improvements:

  • Edge-case handling: Large or malformed RLEs and negative or zero-height/width bounding boxes could pose issues. You might want to clamp or at least warn on out-of-range values.
  • Unit tests: Creating round-trip tests (_mask_to_cvat_rle_rle_to_binary_image_mask → compare original) will help detect off-by-one or indexing issues.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18dde78 and 302cf52.

📒 Files selected for processing (1)
  • fiftyone/utils/cvat.py (4 hunks)
🔇 Additional comments (3)
fiftyone/utils/cvat.py (3)

5947-5949: Consistent approach to rectangle shapes

The new condition branches on shape_type == "rectangle" and correctly maps shapes to "detections". This ensures that bounding boxes become detections in FiftyOne. The logic is straightforward, and no immediate issues stand out.


6461-6510: Consider validating coordinates for mask upload

This code path correctly handles instance segmentation when CVAT ≥ 2.3 by uploading RLE masks, otherwise reverting to polygons. One suggestion:

  • Validate bounding boxes (xtl, ytl, xbr, ybr) or clamp them to [0, width-1] / [0, height-1] to avoid out-of-bounds or negative dimensions.
  • Performance: For very large masks, reconciling memory usage with RLE might be worth testing.

Overall, the fallback to polygon-based representation for older servers is a good approach.


7160-7190: Confirm RLE indexing consistency with upload path

The to_instance() method decodes the last four points as the bounding box and interprets remaining points as RLE. This closely mirrors the upload logic (lines ~6461-6510) but with an opposite +1/-1 offset. Verify these offsets produce the correct mask size, especially near image boundaries.

Additionally, consider gracefully handling cases where xbr <= xtl or ybr <= ytl.

Copy link
Member

@ehofesmann ehofesmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for taking this over the finish line!

@brimoor brimoor merged commit 46bd6bd into develop Jan 2, 2025
14 checks passed
@brimoor brimoor deleted the finalize-4483 branch January 2, 2025 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants