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

yolo8 improvements #55

Merged
merged 14 commits into from
Aug 16, 2024
Merged

yolo8 improvements #55

merged 14 commits into from
Aug 16, 2024

Conversation

Eldies
Copy link

@Eldies Eldies commented Aug 8, 2024

Summary

  1. yolo v8 does not require annotation files anymore
  2. better import for yolo v8 oriented boxes
  3. allowing exporting of skeletons with different sizes in yolov8 pose
  4. renaming yolov8 to yolov8_detection
  5. yolo8 segmentation can now export masks

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 annotation export process to avoid unnecessary calls when there are no annotations.
    • Improved rectangle validation with a robust library function, Streamlining the annotation parsing process.
  • Bug Fixes

    • Expanded dataset comparison logic to include rotation attributes for bounding boxes.
    • Updated test suite to cover scenarios for saving/loading datasets without annotations and handling missing annotation files.
  • Documentation

    • Renamed private function to public, enhancing accessibility for annotation comparison logic.

Copy link

coderabbitai bot commented Aug 8, 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

This update enhances the functionality of the YOLO format plugin in Datumaro by optimizing annotation exports, simplifying rectangle validation using OpenCV, and improving dataset comparison tests. New methods have been introduced for better annotation parsing and handling rotations, while redundant tests have been removed for cleaner code. These changes collectively improve performance, reliability, and test coverage.

Changes

Files Change Summary
datumaro/plugins/yolo_format/converter.py Added _export_item_annotation method to optimize exporting annotations.
datumaro/plugins/yolo_format/extractor.py Removed rectangle validation logic; introduced new method using OpenCV for rectangle checks and added _parse_annotations for improved annotation handling.
datumaro/util/test_utils.py Renamed _compare_annotations to compare_annotations, making it a public function; updated references throughout the code.
tests/unit/data_formats/test_yolo_format.py Enhanced dataset comparison logic and added new test cases; updated setup method to include monkeypatch; removed redundant tests for invalid shapes.

Sequence Diagram(s)

sequenceDiagram
    participant Converter
    participant AnnotationParser
    participant Dataset

    Converter->>AnnotationParser: Export item annotations
    alt If annotations exist
        AnnotationParser->>AnnotationParser: Call superclass method
    else
        AnnotationParser-->>Converter: No annotations to export
    end
Loading

🐰 In the land of code where rabbits hop,
A new method sprouted, making exports stop,
With rectangles snug in a min area hold,
And tests now dance, both brave and bold!
Each change a leap, in the forest of data,
We celebrate progress, oh, how it feels greater! 🥕✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@Eldies Eldies marked this pull request as ready for review August 8, 2024 11:27
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: 1

Outside diff range, codebase verification and nitpick comments (1)
datumaro/util/test_utils.py (1)

118-118: Ensure consistent renaming of _compare_annotations to compare_annotations.

The function _compare_annotations is still referenced in the following locations, which indicates that the renaming change has not been consistently applied throughout the codebase:

  • datumaro/components/operations.py:
    • Line where _compare_annotations is defined.
    • Line where _compare_annotations is used.

Please ensure that these references are updated to compare_annotations to maintain consistency.

Analysis chain

Ensure consistent naming conventions.

The function _compare_annotations has been renamed to compare_annotations, making it public. Ensure that this change is consistently applied throughout the codebase and that the function is documented if it is intended for external use.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all references to `_compare_annotations` have been updated to `compare_annotations`.

# Test: Search for any remaining references to `_compare_annotations`. Expect: No matches.
rg --type python '_compare_annotations'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify that all references to `_compare_annotations` have been updated to `compare_annotations`.

# Test: Search for any remaining references to `_compare_annotations`. Expect: No matches.
rg '_compare_annotations' --glob '*.py'

Length of output: 239

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3f0551 and 16a0541.

Files selected for processing (4)
  • datumaro/plugins/yolo_format/converter.py (1 hunks)
  • datumaro/plugins/yolo_format/extractor.py (5 hunks)
  • datumaro/util/test_utils.py (3 hunks)
  • tests/unit/data_formats/test_yolo_format.py (6 hunks)
Additional comments not posted (10)
datumaro/util/test_utils.py (2)

191-191: Verify function call updates.

Ensure that the compare_annotations function is correctly used in the compare_datasets function. The change should not affect the logic of dataset comparison.


257-257: Verify function call updates.

Ensure that the compare_annotations function is correctly used in the compare_datasets_3d function. The change should maintain the logic of 3D dataset comparison.

datumaro/plugins/yolo_format/converter.py (1)

279-282: Optimize annotation export logic.

The new _export_item_annotation method in YOLOv8Converter ensures that the superclass method is only called when there are annotations present. This optimization prevents unnecessary processing and improves performance when exporting items without annotations.

datumaro/plugins/yolo_format/extractor.py (2)

334-340: Ensure robust annotation parsing.

The _parse_annotations method now checks for the existence of the annotation path before attempting to parse it, returning an empty list if the path does not exist. This change prevents errors from accessing non-existent files and improves robustness.


480-491: Improve rectangle handling with OpenCV.

The use of cv2.minAreaRect simplifies the rectangle validation process, leveraging OpenCV's robust functionality. The rotation normalization to 0-180 degrees should be verified to ensure it aligns with downstream processing requirements.

Verification successful

Rotation normalization verified for downstream compatibility.

The rotation normalization to a 0-180 degree range is consistent with existing logic in the codebase, particularly in test_yolo_format.py, which tests for rotation differences within this range. No evidence suggests reliance on a 0-360 degree range, indicating that downstream processes should not be adversely affected by this change.

  • tests/unit/data_formats/test_yolo_format.py: Confirms handling of rotation differences within 0-180 degrees.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the rotation normalization change on downstream processes.

# Test: Search for downstream processes that rely on rotation values. Expect: Review any logic that assumes a 0-360 degree range.
rg --type python 'rotation'

Length of output: 58


Script:

#!/bin/bash
# Corrected command to search for usage of rotation values in Python files.
rg 'rotation' --type py -A 3

Length of output: 14009

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

62-62: Import of compare_annotations looks good.

The addition of compare_annotations is appropriate for handling dataset comparisons involving annotations.


79-81: Inclusion of monkeypatch in setup method is appropriate.

The addition enhances the flexibility of the test cases by allowing dynamic modifications.


468-474: Addition of test_can_save_and_load_without_annotations is beneficial.

This test case enhances coverage for scenarios where datasets lack annotations.


1155-1160: Addition of test_can_import_with_missing_ann_file is appropriate.

This test case ensures robustness in handling missing annotation files.


89-121: Refactoring of compare_datasets to handle rotations is well-implemented.

The new logic in compare_rotated_annotations effectively manages rotation differences in bounding boxes.

However, ensure that the logic for handling rotations is correctly applied across all relevant test cases.

tests/unit/data_formats/test_yolo_format.py Outdated Show resolved Hide resolved
@Eldies Eldies mentioned this pull request Aug 8, 2024
7 tasks
datumaro/plugins/yolo_format/converter.py Outdated Show resolved Hide resolved
datumaro/plugins/yolo_format/converter.py Outdated Show resolved Hide resolved
datumaro/plugins/yolo_format/converter.py Show resolved Hide resolved
datumaro/util/mask_tools.py Show resolved Hide resolved
datumaro/util/mask_tools.py Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Aug 16, 2024

@SpecLad SpecLad merged commit 125840f into develop Aug 16, 2024
19 checks passed
@SpecLad SpecLad deleted the dl/yolo8-fixes branch August 16, 2024 15:40
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.

2 participants