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

Support 3D object detection annotation on pcd files with CVAT #5458

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ehofesmann
Copy link
Member

@ehofesmann ehofesmann commented Feb 1, 2025

What changes are proposed in this pull request?

This PR adds support for 3d pointcloud annotation, specifically of 3D detections/cuboids, through the integration with CVAT.

3D annotation in CVAT is limited to 3d detections on a single .pcd file (with the option of adding up to 12 reference images). There are multiple directory structures that it supports for this: https://docs.cvat.ai/docs/manual/basics/create_an_annotation_task/#data-formats-for-a-3d-task

Given that 3d datasets in FiftyOne require media to be stored in .fo3d files, annotating them requires an additional step which is on the user to structure the data as needed by cvat, and store the references to that data in an alternate media field on the dataset.
Once that setup is complete, you can send 3d detections with pointcloud data and load them just as you would for 2d labels. See the test for an example.

An example of this has been added to the CVAT integration docs as well.
image

How is this patch tested? If it is not, please explain why.

import fiftyone.zoo as foz
import os

dataset = foz.load_zoo_dataset("quickstart-groups")
view = dataset.select_group_slices("pcd")

# Populate a field on the dataset that points to the data to upload to CVAT
# This data can be as simple as a filepath to a .pcd, or to a zip archive structured like any of these examples: https://docs.cvat.ai/docs/manual/basics/create_an_annotation_task/#data-formats-for-a-3d-task
view.set_values("pcd_filepath", [f.replace(".fo3d", ".pcd") for f in view.values("filepath")])

results = view[1:2].annotate("test", label_field="ground_truth", media_field="pcd_filepath", launch_editor=True)

# Annotate the cuboids in cvat

view.load_annotations("test")

# View the newly loaded/edited cuboids in FiftyOne
session = fo.launch_app(dataset)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

Adds support for annotation of 3D cuboids in pointcloud data through the CVAT integration.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Added support for 3D data annotations, allowing point cloud (.pcd) files to be used alongside images and videos.
    • Enhanced the annotation process by requiring explicit specification for 3D data to ensure correct handling.
  • Documentation

    • Introduced a new section outlining the 3D annotation workflow, detailing preprocessing steps and providing a practical example for setting up 3D datasets.

@ehofesmann ehofesmann added the annotation Issues related to FiftyOne's annotation API label Feb 1, 2025
@ehofesmann ehofesmann self-assigned this Feb 1, 2025
@ehofesmann ehofesmann requested a review from allenleetc February 1, 2025 20:48
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Walkthrough

This update enhances the CVAT integration by introducing support for annotating 3D data. The documentation now includes a section that explains the process of annotating 3D point cloud data, detailing the required file format, preprocessing steps, and an example procedure. Furthermore, the CVAT backend has been updated to recognize a new media type (3D) by modifying several method signatures and incorporating checks for the necessary parameters when processing 3D datasets.

Changes

File(s) Change Summary
docs/source/integrations/cvat.rst Added a new "Annotating 3D data" section explaining the handling of 3D point cloud annotations, preprocessing requirements, and an example cross-referencing a FiftyOne dataset.
fiftyone/utils/cvat.py Updated CVATBackend to include fom.THREE_D in supported media types, and modified upload_samples, upload_data, and shape-related methods to accept a new media_field and an is_3d flag for handling 3D annotations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CVATBackend
    User->>CVATBackend: Calls upload_samples(samples, anno_key, backend, media_field)
    alt 3D Media Provided
        CVATBackend->>CVATBackend: Validate media_field is present
        CVATBackend->>CVATBackend: Process samples with is_3d flag set
        CVATBackend->>User: Successfully uploads 3D data
    else Missing media_field
        CVATBackend-->>User: Raise ValueError (prompting correct usage)
    end
Loading

Suggested labels

feature

Suggested reviewers

  • brimoor

Poem

I'm a rabbit leaping through the code,
With ears up high on this special road.
3D changes hop into action so neat,
Bringing new annotations with a joyful beat.
Celebrate the improvements with a twitch of my nose and a hop of delight!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 (5)
fiftyone/utils/cvat.py (4)

5428-5428: Redundant repetition of is_3d check

You are defining is_3d again for the same purpose (line 4409). Consider refactoring to avoid duplication, for example by using a helper function or consolidating logic once at a higher level.


5957-5959: Consider merging conditional branches

Ruff suggests merging the if det.bounding_box: and else: branches using a logical operator. The current structure is readable, but merging could slightly streamline the code:

🧰 Tools
🪛 Ruff (0.8.2)

5954-5959: Combine if branches using logical or operator

Combine if branches

(SIM114)


6199-6199: is_3d declared again

You redefine is_3d here for a second time. If this is intended, it’s fine; otherwise, you might unify these declarations to avoid confusion and duplication.


7178-7180: Remove unused local variables

The variables location, dimensions, and rotation are assigned but never utilized. Consider removing them to declutter the code:

- location = None
- dimensions = None
- rotation = None
🧰 Tools
🪛 Ruff (0.8.2)

7178-7178: Local variable location is assigned to but never used

Remove assignment to unused variable location

(F841)


7179-7179: Local variable dimensions is assigned to but never used

Remove assignment to unused variable dimensions

(F841)


7180-7180: Local variable rotation is assigned to but never used

Remove assignment to unused variable rotation

(F841)

docs/source/integrations/cvat.rst (1)

2239-2288: New Section for 3D Annotations: Clear and Informative

The new "Annotating 3D data" section is well-written and clearly explains how to work with 3D point cloud data using CVAT. It details the key differences between 2D and 3D workflows, highlights the need for a manual preprocessing step, and instructs users to set the media_field when annotating 3D datasets. The code example effectively demonstrates converting file paths (from .fo3d to .pcd), selecting a group slice, and performing annotation steps, which aligns well with the PR objectives.

Minor suggestion: Consider adding a brief note for users on handling alternative file naming conventions or additional preprocessing scenarios, in case the simple replacement (f.replace(".fo3d", ".pcd")) does not directly apply.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 847015e and 07bf5b9.

📒 Files selected for processing (2)
  • docs/source/integrations/cvat.rst (2 hunks)
  • fiftyone/utils/cvat.py (10 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/utils/cvat.py

5954-5959: Combine if branches using logical or operator

Combine if branches

(SIM114)


7178-7178: Local variable location is assigned to but never used

Remove assignment to unused variable location

(F841)


7179-7179: Local variable dimensions is assigned to but never used

Remove assignment to unused variable dimensions

(F841)


7180-7180: Local variable rotation is assigned to but never used

Remove assignment to unused variable rotation

(F841)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: lint / eslint
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build / build
  • GitHub Check: build
🔇 Additional comments (5)
fiftyone/utils/cvat.py (5)

3255-3255: Extend support to 3D media types

The addition of fom.THREE_D in the return list for supported_media_types is consistent with the broader 3D annotation support introduced in this file.


4409-4409: Detect 3D media at sample level

Assigning is_3d = samples.media_type == fom.THREE_D provides a straightforward check for 3D data. Implementation looks correct.


4410-4417: Require media_field for 3D

Raising an error for 3D samples when the media_field is not set (i.e., still "filepath") clarifies usage and prevents accidental misconfiguration.


5444-5444: Enable single-job tasks for 3D

Using if is_video or is_3d: ensures that 3D data is treated analogously to video in terms of task segmentation. This is coherent, and the change aligns with the new 3D annotation flow.


6215-6217: Setup for single-frame 3D annotation

Leveraging [sample] and an empty frame_size tuple here is a valid approach to process 3D data. Ensure that elsewhere in the pipeline, the absence of traditional width/height attributes is correctly handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
annotation Issues related to FiftyOne's annotation API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant