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

ultralytics yolo support for tracks #8883

Merged
merged 14 commits into from
Jan 7, 2025
Merged

ultralytics yolo support for tracks #8883

merged 14 commits into from
Jan 7, 2025

Conversation

Eldies
Copy link
Contributor

@Eldies Eldies commented Dec 27, 2024

Motivation and context

Can now import Ultralytics Yolo formats with track_id
Can now export Ultralytics Yolo Detection with track_id

depends on cvat-ai/datumaro#70

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

Release Notes

  • New Features

    • Expanded dataset import formats to include multiple YOLO formats.
    • Introduced new classes for annotation transformations: MaskConverter, EllipsesToMasks, MaskToPolygonTransformation, and SetKeyframeForEveryTrackShape.
    • Added support for exporting YOLO detection data with track IDs.
  • Bug Fixes

    • Minor formatting adjustments to ensure existing formats remain intact.
  • Tests

    • Added new export and import formats for "Ultralytics YOLO Detection Track 1.0" in the test suite.
  • Chores

    • Updated the datumaro package to a newer version in requirements files.

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces enhancements to the CVAT dataset manager, focusing on expanding support for YOLO formats and improving annotation transformations. The changes include adding new YOLO-related formats (Ultralytics detection, segmentation, oriented boxes, and pose), implementing new transformation classes for mask and annotation conversions, and updating the necessary test and configuration files to support these new formats.

Changes

File Change Summary
cvat/apps/dataset_manager/bindings.py Added new YOLO Ultralytics formats to track_formats
cvat/apps/dataset_manager/formats/transformations.py Added new classes: MaskConverter, EllipsesToMasks, MaskToPolygonTransformation, SetKeyframeForEveryTrackShape for advanced annotation transformations
cvat/apps/dataset_manager/formats/yolo.py Updated export and import functions with new parameters and added _export_yolo_ultralytics_detection function
cvat/apps/dataset_manager/tests/... Updated test files to include new Ultralytics YOLO Detection Track format
cvat/requirements/base.in and base.txt Updated Datumaro dependency to a new commit hash

Sequence Diagram

sequenceDiagram
    participant DM as Dataset Manager
    participant Converter as Annotation Converter
    participant Exporter as YOLO Exporter
    
    DM->>Converter: Transform annotations
    Converter-->>DM: Converted annotations
    DM->>Exporter: Export dataset
    Exporter-->>DM: Exported YOLO format
Loading

Poem

🐰 Hop, hop, through YOLO's maze,
Transforming masks with rabbitry ways
Ultralytics formats, now so neat
Annotations dance to a new beat!
Dataset magic, pure delight! 🎉


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 1

🧹 Nitpick comments (2)
cvat/apps/dataset_manager/formats/transformations.py (2)

Line range hint 104-119: Double-check ellipse drawing assumptions in EllipsesToMasks.

The ellipse conversion logic looks straightforward. Consider verifying:

  1. Rotation calculations are consistent with the annotation specification.
  2. The image boundary is respected for large ellipses or those near the border.
  3. The ellipse’s integer rounding (using round) doesn’t skip edge pixels for partially included boundaries.

138-145: Ensure no conflicts when overwriting the keyframe attribute.

By setting keyframe=True for every annotation that has a track_id, you override any existing keyframe attributes. If the dataset already has a keyframe set to another value, it will be lost. Consider preserving the original keyframe if it exists.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a25291 and 9b2ce49.

📒 Files selected for processing (8)
  • cvat/apps/dataset_manager/bindings.py (1 hunks)
  • cvat/apps/dataset_manager/formats/transformations.py (4 hunks)
  • cvat/apps/dataset_manager/formats/yolo.py (4 hunks)
  • cvat/apps/dataset_manager/tests/assets/annotations.json (1 hunks)
  • cvat/apps/dataset_manager/tests/test_formats.py (1 hunks)
  • cvat/apps/dataset_manager/tests/test_rest_api_formats.py (1 hunks)
  • cvat/requirements/base.in (1 hunks)
  • cvat/requirements/base.txt (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cvat/apps/dataset_manager/tests/test_rest_api_formats.py
🔇 Additional comments (13)
cvat/apps/dataset_manager/formats/transformations.py (2)

Line range hint 40-103: Evaluate clarity and potential edge cases in MaskConverter.

Overall, the MaskConverter class is logically cohesive and uses COCO RLE encoding properly. However, ensure that:

  1. The bounding box offsets (left, top, right, bottom) don’t exceed image boundaries for edge-case shapes.
  2. Large masks are handled efficiently to avoid unnecessary memory overhead.
  3. Potential corner cases (e.g., immediate zero-width or zero-height masks) are tested.

Line range hint 120-135: Confirm conversion skip logic in MaskToPolygonTransformation.

The transformation is only applied if conv_mask_to_poly is true (default). Make sure that:

  1. dataset.transform('masks_to_polygons') respects the segmentation definitions in all annotation types.
  2. There's a test or fallback for shapes that are not strictly masks, to avoid potential runtime issues.
cvat/apps/dataset_manager/formats/yolo.py (7)

7-7: Importing Optional and Callable is helpful for clarity.

Good job including type hints for readability and maintainability.


26-26: SetKeyframeForEveryTrackShape import aligns transformations across modules.

Including this transformation in YOLO logic ensures consistent track annotation post-import.


29-37: New parameter write_track_id in _export_common enhances track ID support.

Providing a boolean toggle for track ID export is an elegant way to maintain backward compatibility and add new functionality.


40-40: Passing write_track_id to dataset.export is correct.

This effectively links the new parameter to your dataset logic for YOLO exports.


52-57: Type hints for _import_common improve function clarity.

The typed parameters facilitate better tooling support (IDE hints, static analysis) and reduce confusion about expected argument types.


82-82: Applying SetKeyframeForEveryTrackShape after import.

Ensuring each imported annotation with a track_id has keyframe=True is consistent with the new track-based YOLO workflows, but watch for potential collisions with existing keyframe states as noted in the transformations file.


98-101: Dedicated exporter for Ultralytics YOLO Detection Track.

Introducing _export_yolo_ultralytics_detection with write_track_id=True is consistent with your track annotation changes. This isolates new format logic, avoiding confusion with existing YOLO exporters.

cvat/apps/dataset_manager/tests/test_formats.py (1)

298-298: New format 'Ultralytics YOLO Detection Track 1.0' aligns with track-based enhancements.

Explicitly enumerating the new format in the test suite validates the workflow for track-based YOLO detection. Verify that test coverage includes exporting and importing actual track data.

cvat/apps/dataset_manager/bindings.py (1)

2178-2182: Looks good extending track formats to Ultralytics YOLO variants.

These entries are consistent with the existing approach for specifying track-compatible formats. No issues detected.

cvat/requirements/base.txt (1)

59-59: Upgrade Datumaro revision with caution.

Upgrading to the new commit may introduce breaking changes. Please verify that all dependent features and tests remain stable.

cvat/apps/dataset_manager/tests/assets/annotations.json (1)

1011-1057: New test entry for "Ultralytics YOLO Detection Track 1.0" increases coverage.

The example includes both shapes and tracks, showcasing outside and keyframe flags, which is helpful for validating correct track extraction. This addition aligns well with the new YOLO track features.

cvat/requirements/base.in Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.93%. Comparing base (5702a04) to head (18c1141).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8883      +/-   ##
===========================================
- Coverage    73.93%   73.93%   -0.01%     
===========================================
  Files          411      411              
  Lines        44223    44237      +14     
  Branches      3993     3993              
===========================================
+ Hits         32698    32705       +7     
- Misses       11525    11532       +7     
Components Coverage Δ
cvat-ui 78.37% <ø> (-0.04%) ⬇️
cvat-server 70.16% <100.00%> (+0.02%) ⬆️

@Eldies Eldies requested a review from azhavoro as a code owner January 2, 2025 09:34
# Conflicts:
#	cvat/apps/dataset_manager/formats/yolo.py
#	cvat/requirements/base.in
#	cvat/requirements/base.txt
@@ -67,6 +79,7 @@ def _import_common(
detect_dataset(temp_dir, format_name=format_name, importer=dm_env.importers.get(format_name))
dataset = Dataset.import_from(temp_dir, format_name,
env=dm_env, image_info=image_info, **(import_kwargs or {}))
dataset = dataset.transform(SetKeyframeForEveryTrackShape)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if an annotation's attributes does not contain keyframe, the execution goes here: https://github.com/cvat-ai/cvat/blob/develop/cvat/apps/dataset_manager/bindings.py#L2260 and does not go here: https://github.com/cvat-ai/cvat/blob/develop/cvat/apps/dataset_manager/bindings.py#L2300
and therefore track is not recognised as track and _validate_track_shapes is not executed for it

Copy link
Contributor

@zhiltsov-max zhiltsov-max left a comment

Choose a reason for hiding this comment

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

Please update changelog, it's a noticeable change.

@Eldies Eldies requested a review from nmanovic as a code owner January 7, 2025 12:36
@Eldies
Copy link
Contributor Author

Eldies commented Jan 7, 2025

Please update changelog, it's a noticeable change.

done

Copy link

sonarqubecloud bot commented Jan 7, 2025

@zhiltsov-max zhiltsov-max merged commit 8b621c2 into develop Jan 7, 2025
35 checks passed
@zhiltsov-max zhiltsov-max deleted the dl/yolo-tracks branch January 7, 2025 14:40
This was referenced Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants