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

keep original rotation on import-export in yolo oriented boxes #72

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

Conversation

Eldies
Copy link

@Eldies Eldies commented Dec 30, 2024

Summary

How to test

Checklist

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.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2022 CVAT.ai Corporation
#
# SPDX-License-Identifier: MIT

Summary by CodeRabbit

  • New Features

    • Enhanced bounding box annotation processing for YOLO Ultralytics format
    • Improved synchronization of imported and exported annotations
  • Refactor

    • Made bbox_annotation_as_polygon function public
    • Simplified rotation comparison logic in test suite
  • Bug Fixes

    • Improved handling of rotated bounding box annotations

Copy link

coderabbitai bot commented Dec 30, 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 changes to the YOLO format plugin in Datumaro, focusing on bounding box and polygon annotation handling. The modifications include making a function public in the converter, adding a rotation synchronization method in the extractor, and updating the dataset comparison logic in the test suite. These changes aim to improve the handling of oriented bounding boxes and their transformations across different stages of annotation processing.

Changes

File Change Summary
src/datumaro/plugins/yolo_format/converter.py Made _bbox_annotation_as_polygon a public method bbox_annotation_as_polygon
src/datumaro/plugins/yolo_format/extractor.py Added _rotate_bbox_to_sync_exported_annotation_with_imported method to YoloUltralyticsOrientedBoxesExtractor
Updated _load_one_annotation to use the new rotation method
tests/unit/data_formats/test_yolo_format.py Modified compare_datasets method in CompareDatasetsRotationMixin
Changed rotation difference calculation to use 360-degree modulus

Sequence Diagram

sequenceDiagram
    participant Converter
    participant Extractor
    participant Annotation

    Converter->>Annotation: bbox_annotation_as_polygon()
    Extractor->>Annotation: _rotate_bbox_to_sync_exported_annotation_with_imported()
    Annotation-->>Extractor: Adjusted Bounding Box
Loading

Poem

🐰 Hop, hop, through YOLO's maze,
Bounding boxes dance and sway,
Rotations sync with rabbit's grace,
Polygons transform without delay,
Code leaps forward, bright and bold! 🌟


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

@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)
src/datumaro/plugins/yolo_format/extractor.py (1)

505-548: Consider documenting assumptions and edge cases for _rotate_bbox_to_sync_exported_annotation_with_imported.

The logic for determining the best shift is correct and well-organized, but there's no immediate check if imported_points has exactly 4 corners — relying on the caller to handle input validation. Adding a short docstring or inline comment would clarify the requirement that both imported_points and exported_points represent quadrilaterals and help future maintainers grasp the shift-by-90° increments concept more easily.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a3ed10b and 79dd809.

📒 Files selected for processing (3)
  • src/datumaro/plugins/yolo_format/converter.py (2 hunks)
  • src/datumaro/plugins/yolo_format/extractor.py (3 hunks)
  • tests/unit/data_formats/test_yolo_format.py (1 hunks)
🔇 Additional comments (5)
src/datumaro/plugins/yolo_format/extractor.py (2)

48-48: Good move making bbox_annotation_as_polygon accessible.

Importing the newly public function is consistent with the refactor, ensuring reusability across modules.


571-580: Thorough integration of rotation synchronization.

The adjustment of the bounding box attributes post-cv2.minAreaRect() via _rotate_bbox_to_sync_exported_annotation_with_imported is logically coherent, ensuring consistent orientation across imports and exports. The final assignment of rotation attributes appears correct and covers the edge case of near-zero rotation by removing the attribute. Good job.

tests/unit/data_formats/test_yolo_format.py (1)

101-104: Simplified rotation comparison.

Switching from modulo 180 to 360 and removing the extra 90°-handling logic yields a simpler approach that only treats bounding boxes as matching when their rotation differences are negligible (less than 0.01). However, this disallows bounding boxes rotated by 180° or 90° from matching, which might be a breaking change depending on prior requirements. Confirm that this strict rotation check aligns with the new bounding-box sync logic in the extractor.

src/datumaro/plugins/yolo_format/converter.py (2)

49-49: Public function promotes clearer usage.

Renaming _bbox_annotation_as_polygon to bbox_annotation_as_polygon is a good accessibility improvement, making it available for external references. The rotation logic inside is straightforward.


349-349: Good integration of bbox_annotation_as_polygon in oriented boxes converter.

This call consolidates rectangle-to-polygon conversions without code duplication, adhering to DRY principles.

Copy link

sonarqubecloud bot commented Jan 3, 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.

1 participant