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

Fix quality computation for tasks with skeletons and normal labels #8100

Merged
merged 5 commits into from
Jul 3, 2024

Conversation

zhiltsov-max
Copy link
Contributor

@zhiltsov-max zhiltsov-max commented Jun 28, 2024

Motivation and context

  • Fixed quality report computation in tasks with non-skeleton labels after skeleton labels

How has this been tested?

Unit tests

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

  • Bug Fixes

    • Improved quality computation for tasks with both skeletons and normal labels in the Computer Vision Annotation Tool (CVAT).
  • Tests

    • Added a new test to ensure quality can be computed correctly when a non-skeleton label follows a skeleton label.

Copy link
Contributor

coderabbitai bot commented Jun 28, 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 quality computation in the Computer Vision Annotation Tool (CVAT) by addressing how tasks with skeleton and normal labels are managed. A new parameter, label_id_mapper, was introduced to refine the confusion matrix creation and shape matching processes. Additionally, a test was added to verify the quality computation when labels transition from skeleton to non-skeleton.

Changes

File Change Summary
cvat/apps/quality_control/quality_reports.py Introduced label_id_mapper parameter in _make_zero_confusion_matrix and modified its usage in _find_closest_unmatched_shape.
tests/python/rest_api/test_quality_control.py Added test_can_compute_quality_if_non_skeleton_label_follows_skeleton_label to verify quality computation scenarios.

Poem

In the fields where labels dance,
A mapper joined for clearer chance.
Shapes aligned with mindful grace,
A test to see if quality’s place.
Skeletons and labels, side by side,
Now in harmony, they glide. 🌟🛠️


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 Configration 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.

@zhiltsov-max zhiltsov-max changed the title Fix quality computation for task with skeletons and normal labels Fix quality computation for tasks with skeletons and normal labels Jun 28, 2024
@zhiltsov-max
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Outside diff range and nitpick comments (1)
cvat/apps/quality_control/quality_reports.py (1)

[!TIP]
Codebase Verification

Missing label_id_mapper Parameter in _make_zero_confusion_matrix Calls

The _make_zero_confusion_matrix method requires a label_id_mapper parameter for correct functionality. However, the following instances do not include this parameter:

  • cvat/apps/quality_control/quality_reports.py, line 1973
  • cvat/apps/quality_control/quality_reports.py, line 1995

Please ensure that the label_id_mapper parameter is provided in these method calls.

Analysis chain

Line range hint 1933-1992: Refactor _make_zero_confusion_matrix method to include label_id_mapper

The changes to the _make_zero_confusion_matrix method include the addition of a label_id_mapper parameter and its usage in the method. This modification is essential for correctly mapping label IDs to indices in the confusion matrix, which is crucial for handling tasks with both skeleton and non-skeleton labels correctly.

  • Ensure that the label_id_mapper is always provided when this method is called.
  • Verify that the label_id_mapper function is thoroughly tested, especially its ability to handle unexpected or edge case inputs.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `label_id_mapper` is provided everywhere `_make_zero_confusion_matrix` is called.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type python $'_make_zero_confusion_matrix'

Length of output: 77



Script:

#!/bin/bash
# Description: Verify that `label_id_mapper` is provided everywhere `_make_zero_confusion_matrix` is called.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type py '_make_zero_confusion_matrix'

Length of output: 389



Script:

#!/bin/bash
# Description: Display the surrounding lines of the calls to `_make_zero_confusion_matrix` to verify if `label_id_mapper` is included.

# Show surrounding lines for the first call
rg --type py '_make_zero_confusion_matrix()' -A 3 -B 3

# Show surrounding lines for the second call
rg --type py '_make_zero_confusion_matrix()' -A 3 -B 3

Length of output: 3853

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ccc29d and a2edc0b.

Files selected for processing (3)
  • changelog.d/20240628_183747_mzhiltso_fix_quality_for_skeletons.md (1 hunks)
  • cvat/apps/quality_control/quality_reports.py (3 hunks)
  • tests/python/rest_api/test_quality_control.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • changelog.d/20240628_183747_mzhiltso_fix_quality_for_skeletons.md
Additional comments not posted (2)
tests/python/rest_api/test_quality_control.py (1)

1248-1281: Ensure proper cleanup and isolation in tests.

This test modifies task labels and annotations which could affect other tests if not properly isolated or cleaned up. Consider using fixtures for setup and teardown to ensure test isolation.

Verification successful

Proper cleanup and isolation verified.

The restore_db_per_class fixture is used in the autouse fixtures, ensuring that the database state is reset between tests. This provides the necessary cleanup and isolation for the tests.

  • restore_db_per_class fixture is defined in tests/python/shared/fixtures/init.py and restores the database state using docker_restore_db or kube_restore_db.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for usage of fixtures that ensure proper cleanup and isolation.

# Search for pytest fixtures related to database restoration or cleanup.
rg --type python '@pytest.fixture' 'tests/python/rest_api/test_quality_control.py'

Length of output: 111



Script:

#!/bin/bash
# Description: Check for usage of fixtures that ensure proper cleanup and isolation.

# Search for pytest fixtures related to database restoration or cleanup.
rg --type py '@pytest.fixture' 'tests/python/rest_api/test_quality_control.py'

Length of output: 178



Script:

#!/bin/bash
# Description: Extract definitions of pytest fixtures to check for proper cleanup and isolation.

# Search for the definitions of pytest fixtures in the test file.
rg --type py '@pytest.fixture' -A 10 'tests/python/rest_api/test_quality_control.py'

Length of output: 1447



Script:

#!/bin/bash
# Description: Extract the definition of the `restore_db_per_class` fixture to verify its role in test isolation.

# Search for the definition of the `restore_db_per_class` fixture.
rg --type py 'def restore_db_per_class' -A 10

Length of output: 757

cvat/apps/quality_control/quality_reports.py (1)

1943-1944: Use of label_id_mapper in _generate_frame_annotation_conflicts method

The label_id_mapper is correctly utilized to map label IDs to their corresponding indices in the confusion matrix. This is a crucial aspect of ensuring that labels are correctly accounted for in the confusion matrix, particularly when handling tasks with a mix of skeleton and non-skeleton labels.

  • Double-check that the label_id_mapper handles all possible label IDs correctly, including any that might not be directly mapped due to errors or omissions in the dataset.
Verification successful

Use of label_id_mapper in _generate_frame_annotation_conflicts method

The label_id_mapper is correctly utilized to map label IDs to their corresponding indices in the confusion matrix. This is a crucial aspect of ensuring that labels are correctly accounted for in the confusion matrix, particularly when handling tasks with a mix of skeleton and non-skeleton labels.

  • The label_id_mapper is defined as label_id_idx_map.__getitem__, which ensures proper mapping of label IDs to their indices.
  • The usage of label_id_mapper in the _generate_frame_annotation_conflicts method appears to handle both ds_ann.label and gt_ann.label correctly, defaulting to _UNMATCHED_IDX when necessary.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all label IDs are correctly handled by `label_id_mapper`.

# Test: Search for the function usage and verify proper mapping.
rg --type python $'label_id_mapper'

Length of output: 65



Script:

#!/bin/bash
# Description: Verify that all label IDs are correctly handled by `label_id_mapper`.

# Test: Search for the function usage and verify proper mapping.
rg --type py $'label_id_mapper'

Length of output: 627

tests/python/rest_api/test_quality_control.py Show resolved Hide resolved
tests/python/rest_api/test_quality_control.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.64%. Comparing base (6d49b89) to head (ab1a977).
Report is 5 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8100   +/-   ##
========================================
  Coverage    83.63%   83.64%           
========================================
  Files          383      383           
  Lines        40503    40507    +4     
  Branches      3831     3830    -1     
========================================
+ Hits         33876    33881    +5     
+ Misses        6627     6626    -1     
Components Coverage Δ
cvat-ui 79.68% <ø> (-0.01%) ⬇️
cvat-server 87.26% <100.00%> (+<0.01%) ⬆️

@zhiltsov-max zhiltsov-max requested review from SpecLad and removed request for nmanovic, azhavoro and Marishka17 July 1, 2024 12:13
cvat/apps/quality_control/quality_reports.py Outdated Show resolved Hide resolved
cvat/apps/quality_control/quality_reports.py Outdated Show resolved Hide resolved
cvat/apps/quality_control/quality_reports.py Outdated Show resolved Hide resolved
tests/python/rest_api/test_quality_control.py Show resolved Hide resolved

max_label_id = label_id

label_id_idx_map[max_label_id + 1] = len(label_names)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? It shouldn't be possible for the client(s) of this function to index the map with this key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed to make the matrix size and label names list the same size, mostly to avoid confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's still confusing, because max_label_id + 1 can be a valid label ID (if there's a sublabel following the last non-sublabel). IMO, this map entry is unnecessary and you shouldn't add it.

Copy link

sonarcloud bot commented Jul 2, 2024

@zhiltsov-max zhiltsov-max merged commit f886f83 into develop Jul 3, 2024
33 checks passed
@zhiltsov-max zhiltsov-max deleted the zm/fix-quality-for-skeletons branch July 3, 2024 09:43
@cvat-bot cvat-bot bot mentioned this pull request Jul 15, 2024
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