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

Add a quality setting for avoiding using bbox in point group matching #8634

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

Conversation

zhiltsov-max
Copy link
Contributor

@zhiltsov-max zhiltsov-max commented Nov 1, 2024

Motivation and context

In some cases point groups do not represent a single object or a bounding box attached to the group does not represent the object. A new quality check option is added for such cases. The new option allows to control whether to use the bbox for point group comparisons or not.

  • Added a new quality setting to enable or disable using of group bbox for point group comparisons

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

    • Introduced a quality setting allowing users to compare point groups without bounding boxes, enhancing flexibility in point comparison methods.
    • Added a new checkbox in the Quality Settings Form for toggling the use of image space in point group comparisons, complete with a tooltip for guidance.
  • Bug Fixes

    • Improved handling of point comparisons by integrating the new image space setting into existing logic, ensuring accurate distance calculations.
  • Documentation

    • Updated changelog to reflect new features and settings related to point group comparisons.

@zhiltsov-max zhiltsov-max marked this pull request as draft November 1, 2024 12:14
Copy link
Contributor

coderabbitai bot commented Nov 1, 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

A new quality setting has been introduced that allows for comparing point groups in image space without using bounding boxes. This change involves updates across multiple files, including the addition of properties and methods in the QualitySettings class, modifications to the QualitySettingsForm component, and updates to the QualitySettingsSerializer. Additionally, a migration file has been created to add a new Boolean field to the qualitysettings model, facilitating the configuration of this new feature.

Changes

File Path Change Summary
changelog.d/20241101_140759_mzhiltso_compare_point_groups_in_image_space.md Added documentation for new quality setting for comparing point groups without bbox.
cvat-core/src/quality-settings.ts Added private property #useImageSpaceForPointGroupComparisons, along with getter, setter, and updated toJSON method.
cvat-core/src/server-response-types.ts Added property use_image_space_for_point_group_comparisons to SerializedQualitySettingsData interface.
cvat-ui/src/components/quality-control/quality-control-page.tsx Added useImageSpaceForPointGroupComparisons to settings object in onSaveQualitySettings.
cvat-ui/src/components/quality-control/task-quality/quality-settings-form.tsx Added useImageSpaceForPointGroupComparisons to initialValues and created a new checkbox in the form.
cvat/apps/quality_control/migrations/0004_qualitysettings_use_image_space_for_point_group_comparisons.py Introduced migration for new field use_image_space_for_point_group_comparisons in qualitysettings model.
cvat/apps/quality_control/models.py Added Boolean field use_image_space_for_point_group_comparisons to QualitySettings model.
cvat/apps/quality_control/quality_reports.py Added use_image_space_for_point_group_comparisons to ComparisonParameters and _DistanceComparator classes, modifying distance calculations.
cvat/apps/quality_control/serializers.py Added use_image_space_for_point_group_comparisons to QualitySettingsSerializer with help text.

Poem

In fields of code, a change takes flight,
Comparing points in image light.
No bounding boxes, just pure grace,
Quality settings find their place.
With checkboxes bright, the users cheer,
A leap in logic, let’s all draw near! 🐇✨


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

@zhiltsov-max zhiltsov-max marked this pull request as ready for review November 1, 2024 13:19
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

🧹 Outside diff range and nitpick comments (8)
changelog.d/20241101_140759_mzhiltso_compare_point_groups_in_image_space.md (1)

1-4: Enhance the changelog entry with more context.

While the entry follows the correct format, it could be more informative for users by briefly explaining the purpose and impact of this feature.

Consider expanding the description like this:

### Added

- A quality setting to compare point groups without using bbox
+ - Added a configurable quality setting to compare point groups in image space without using bounding boxes (bbox).
+   This improves accuracy when point groups or their bounding boxes don't accurately represent single objects.
  (<https://github.com/cvat-ai/cvat/pull/8634>)
cvat/apps/quality_control/serializers.py (2)

102-104: LGTM: Default value configuration is appropriate

The default value of False maintains backward compatibility, and the implementation follows the established pattern.

Consider condensing the nested setdefault into a single line for consistency with other similar configurations:

-        extra_kwargs.setdefault("use_image_space_for_point_group_comparisons", {}).setdefault(
-            "default", False
-        )
+        extra_kwargs.setdefault("use_image_space_for_point_group_comparisons", {"default": False})

126-130: Enhance help text with performance implications

The help text clearly explains the feature's purpose and use cases. Consider adding information about any performance implications of using image space comparisons versus bounding box comparisons.

Suggested addition to the help text:

             "use_image_space_for_point_group_comparisons": """
                 Compare point groups in the image space, instead of using the point group bbox.
                 Useful if point groups may not represent a single object or grouped boxes
                 do not represent object boundaries.
+                Note: Image space comparisons may have different performance characteristics
+                compared to bbox-based comparisons.
             """,
cvat/apps/quality_control/models.py (1)

208-209: LGTM! Consider adding field documentation.

The new field is well-integrated into the model and follows the established patterns. However, it would be helpful to add a docstring to document its purpose and behavior.

Add a docstring to explain the field's purpose:

+    # Controls whether to use image space coordinates instead of bounding boxes
+    # when comparing point groups. When True, point coordinates are compared directly
+    # in the image space. When False, their bounding boxes are used for comparison.
     use_image_space_for_point_group_comparisons = models.BooleanField(default=False)
cvat-core/src/quality-settings.ts (1)

84-90: Consider adding input validation to the setter.

While the getter/setter implementation is functionally correct, consider adding validation in the setter to ensure the input value meets any required constraints.

 set useImageSpaceForPointGroupComparisons(newVal: boolean) {
+    if (typeof newVal !== 'boolean') {
+        throw new Error('useImageSpaceForPointGroupComparisons must be a boolean value');
+    }
     this.#useImageSpaceForPointGroupComparisons = newVal;
 }
cvat-core/src/server-response-types.ts (1)

250-250: LGTM! Consider adding JSDoc comments.

The new property use_image_space_for_point_group_comparisons is well-integrated into the interface and follows the established naming conventions. To improve maintainability, consider adding JSDoc comments to document the purpose and impact of this setting.

Example documentation:

/**
 * When true, point group comparisons are performed in image space without using bounding boxes.
 * This is useful when point groups may not accurately represent a single object or when
 * the associated bounding box does not correctly depict the object.
 */
use_image_space_for_point_group_comparisons?: boolean;
cvat-ui/src/components/quality-control/task-quality/quality-settings-form.tsx (1)

257-280: Consider removing unnecessary required rule from checkbox.

The point comparison section is well-implemented and follows the component's established patterns. However, the rules={[{ required: true }]} on line 272 is unnecessary for a checkbox as it always has a boolean value (true/false).

 <Form.Item
     name='useImageSpaceForPointGroupComparisons'
     valuePropName='checked'
-    rules={[{ required: true }]}
 >

Otherwise, the implementation looks good:

  • Consistent section structure with other form sections
  • Proper use of Ant Design's checkbox component
  • Logical placement in the form's layout
cvat/apps/quality_control/quality_reports.py (1)

1311-1316: Consider improving code organization and comments.

  1. The early exit comment could be more precise: "Early exit for non-overlapping bounding boxes, except for points forming an axis-aligned line"
  2. Remove the blank line at 1314 to maintain logical grouping of the bbox-related code.
 if dm.ops.bbox_iou(a_bbox, b_bbox) <= 0:
-    # this early exit may not work for points forming an axis-aligned line
+    # Early exit for non-overlapping bounding boxes,
+    # except for points forming an axis-aligned line
     return 0

-
 bbox = dm.ops.mean_bbox([a_bbox, b_bbox])
 scale = bbox[2] * bbox[3]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f0a578a and af6e862.

📒 Files selected for processing (9)
  • changelog.d/20241101_140759_mzhiltso_compare_point_groups_in_image_space.md (1 hunks)
  • cvat-core/src/quality-settings.ts (4 hunks)
  • cvat-core/src/server-response-types.ts (1 hunks)
  • cvat-ui/src/components/quality-control/quality-control-page.tsx (1 hunks)
  • cvat-ui/src/components/quality-control/task-quality/quality-settings-form.tsx (3 hunks)
  • cvat/apps/quality_control/migrations/0004_qualitysettings_use_image_space_for_point_group_comparisons.py (1 hunks)
  • cvat/apps/quality_control/models.py (1 hunks)
  • cvat/apps/quality_control/quality_reports.py (5 hunks)
  • cvat/apps/quality_control/serializers.py (3 hunks)
🔇 Additional comments (14)
cvat/apps/quality_control/migrations/0004_qualitysettings_use_image_space_for_point_group_comparisons.py (2)

1-18: LGTM! Migration looks well-structured and backward compatible.

The migration properly adds the new boolean field with a sensible default value that preserves existing behavior.


8-10: Verify migration dependency chain.

Let's ensure this migration is properly ordered in the dependency chain.

✅ Verification successful

Let me check the content of these migrations to verify the dependency chain properly.


Migration dependency chain is correctly ordered

The migration dependencies form a proper linear chain:

  • 0001_initial depends on engine migration
  • 0002_qualityreport_assignee depends on 0001_initial
  • 0003_qualityreport_assignee_last_updated_and_more depends on 0002
  • 0004_qualitysettings_use_image_space_for_point_group_comparisons depends on 0003
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any parallel migrations that might conflict
# Expected: Should only see migrations up to 0003 and this new 0004

# List all migration files in chronological order
fd --type f "^[0-9]{4}.+\.py$" "cvat/apps/quality_control/migrations" --exec ls -l {} \;

Length of output: 601


Script:

#!/bin/bash
# Check the dependencies declared in each migration file
for file in $(fd --type f "^[0-9]{4}.+\.py$" "cvat/apps/quality_control/migrations"); do
    echo "=== $file ==="
    rg "dependencies = " -A 2 "$file"
done

Length of output: 1988

cvat/apps/quality_control/serializers.py (2)

84-84: LGTM: Field addition is well-structured

The new field use_image_space_for_point_group_comparisons is appropriately added to the fields tuple and follows the existing naming conventions.


84-84: Verify integration with related components

The serializer changes look good, but let's verify the integration with related components.

Also applies to: 102-104

✅ Verification successful

Let me verify the implementation details of this field to ensure complete integration.


Let me check one more thing to verify the UI implementation since the previous path wasn't found.


Integration verification complete - all components properly aligned

The field is correctly integrated across all required components:

  • Model: Defined as a BooleanField with default=False
  • Migration: Proper migration file with correct field definition
  • UI: Implemented in both quality-settings-form and quality-control-page with form validation and state management
  • Serializer: Correctly included in the fields list
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent implementation across related files

# Test 1: Verify model field definition
echo "Checking model definition..."
rg -l "use_image_space_for_point_group_comparisons" "cvat/apps/quality_control/models.py"

# Test 2: Check for corresponding UI component
echo "Checking UI implementation..."
rg -l "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control/"

# Test 3: Verify migration file exists
echo "Checking migration file..."
fd -g "*use_image_space_for_point_group_comparisons*.py" "cvat/apps/quality_control/migrations/"

Length of output: 752


Script:

#!/bin/bash
# Check model field definition
echo "Model field definition:"
rg -A 2 "use_image_space_for_point_group_comparisons" "cvat/apps/quality_control/models.py"

# Check UI implementation details
echo -e "\nUI implementation:"
rg -A 2 "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control/quality-settings-form.tsx"

# Check migration content
echo -e "\nMigration details:"
cat "cvat/apps/quality_control/migrations/0004_qualitysettings_use_image_space_for_point_group_comparisons.py"

Length of output: 1188


Script:

#!/bin/bash
# Find the correct UI file location
echo "Finding UI files:"
fd "quality-settings-form" .

# Check UI implementation in found files
echo -e "\nUI implementation details:"
rg -A 2 "useImageSpaceForPointGroupComparisons" $(fd "quality-settings-form" .)

# Check quality control page implementation
echo -e "\nQuality control page implementation:"
rg -A 2 "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control/quality-control-page.tsx"

Length of output: 1204

cvat-core/src/quality-settings.ts (4)

25-25: LGTM: Property declaration follows best practices.

The new private property is well-named, properly typed, and logically placed within the class structure.


46-46: LGTM: Constructor initialization is consistent.

The property is correctly initialized from the server data, maintaining the established pattern of snake_case to camelCase conversion.


210-210: LGTM: JSON serialization maintains consistency.

The property is correctly serialized using snake_case, maintaining consistency with the server-side naming convention.


25-25: Verify integration with quality control components.

The new quality setting appears well-implemented, but let's verify its integration:

Also applies to: 46-46, 84-90, 210-210

✅ Verification successful

Let me check the actual implementation details to ensure proper integration.


Integration verified successfully - all components properly implement the new setting

The new quality setting useImageSpaceForPointGroupComparisons is properly integrated across all necessary components:

  • UI components handle the setting in forms and state management
  • Database migration is in place with proper default value
  • Quality report implementation uses the setting for point group comparisons logic
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new quality setting across the codebase

# Test 1: Check for UI components using this setting
echo "Checking UI components..."
rg -l "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control"

# Test 2: Check for proper migration handling
echo "Checking migrations..."
rg -l "use_image_space_for_point_group_comparisons" "cvat/apps/quality_control/migrations"

# Test 3: Check quality report implementation
echo "Checking quality report implementation..."
rg -l "use_image_space_for_point_group_comparisons" "cvat/apps/quality_control/quality_reports.py"

Length of output: 771


Script:

#!/bin/bash
# Check the implementation details in UI components
echo "Checking UI component implementations..."
rg -A 5 "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control"

# Check migration content
echo "Checking migration implementation..."
cat "cvat/apps/quality_control/migrations/0004_qualitysettings_use_image_space_for_point_group_comparisons.py"

# Check quality report usage
echo "Checking quality report usage..."
rg -A 5 "use_image_space_for_point_group_comparisons" "cvat/apps/quality_control/quality_reports.py"

Length of output: 5442

cvat-ui/src/components/quality-control/quality-control-page.tsx (1)

228-228: LGTM! Verify form implementation.

The addition of useImageSpaceForPointGroupComparisons follows the established pattern for boolean settings. The implementation is correct and consistent with other similar settings in the quality control page.

Let's verify the form implementation to ensure the setting is properly exposed to users:

✅ Verification successful

The search results show that the form implementation is complete and consistent. The new setting is properly:

  1. Initialized from settings
  2. Has a tooltip with description
  3. Implemented as a checkbox form field with proper name and validation

Let me verify the type definitions to ensure full type safety:


Implementation verified and complete

The new setting useImageSpaceForPointGroupComparisons is properly implemented with:

  • Type-safe boolean property in QualitySettings class
  • Complete form integration with checkbox, tooltip, and validation
  • Consistent getter/setter implementation
  • Proper serialization for API communication
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the form component properly implements the new setting

# Look for the form field implementation
rg -A 5 "useImageSpaceForPointGroupComparisons" "cvat-ui/src/components/quality-control/task-quality/"

Length of output: 2349


Script:

#!/bin/bash
# Check type definitions for the new setting
rg -A 2 "useImageSpaceForPointGroupComparisons" "cvat-core/src/"

Length of output: 1477

cvat-ui/src/components/quality-control/task-quality/quality-settings-form.tsx (2)

38-38: LGTM: Initial value setup is correct.

The new setting is properly initialized from the settings prop, following the established patterns in the codebase.


93-96: LGTM: Tooltip implementation follows established patterns.

The tooltip is correctly implemented using the existing helper functions and properly sources its description from the settings object.

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

190-191: LGTM: Well-documented parameter addition.

The new parameter is clearly named, has an appropriate default value for backward compatibility, and includes a descriptive docstring.


961-961: LGTM: Clean parameter integration in _DistanceComparator.

The new parameter is properly integrated into the constructor and initialized with a matching docstring.

Also applies to: 975-979


1306-1310: LGTM: Clear implementation of the point comparison space selection.

The logic for choosing between image space and bbox space is well-implemented and maintains backward compatibility.

…-space' into zm/compare-point-groups-in-image-space
@codecov-commenter
Copy link

codecov-commenter commented Nov 2, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 74.29%. Comparing base (ceba1b7) to head (51f757f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8634      +/-   ##
===========================================
- Coverage    74.30%   74.29%   -0.02%     
===========================================
  Files          401      401              
  Lines        43419    43433      +14     
  Branches      3951     3951              
===========================================
+ Hits         32263    32268       +5     
- Misses       11156    11165       +9     
Components Coverage Δ
cvat-ui 78.63% <60.00%> (-0.02%) ⬇️
cvat-server 70.57% <27.27%> (-0.01%) ⬇️

Copy link

sonarcloud bot commented Nov 4, 2024

@@ -205,6 +205,8 @@ class QualitySettings(models.Model):

low_overlap_threshold = models.FloatField()

use_bbox_size_for_points = models.BooleanField()
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered using an enum for this? E.g. call it points_size_method and have the values be bbox_size and image_size. Neither of these methods seems particularly "true" or "false" to me, so perhaps an enum would be more understandable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's hard to say currently if there are going to be more methods in future. Basically, you can represent any boolean as a enum. I think currently it's premature.

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.

4 participants