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

Fixing import and export issues with invalid tracks #8553

Merged
merged 14 commits into from
Oct 24, 2024

Conversation

Eldies
Copy link
Contributor

@Eldies Eldies commented Oct 17, 2024

Motivation and context

Sometimes tracks have duplicated shapes and export/import fails here:

assert curr_frame > prev_shape["frame"], f"{curr_frame} > {prev_shape['frame']}. Track id: {track['id']}" # Catch invalid tracks

it can be reproduced with following task backup (export fails):
InvalidTracksTaskBackup.zip
Also it can be reproduced with following CVAT 1.1 annotations (import to the task above fails)
InvalidImportAnnotations.zip

PR fixes #8411

And (probably) fixes the following issues:
#4968
#5638
#6779

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

  • New Features

    • Enhanced annotation management with improved filtering and interpolation of shapes and tracks.
    • Added new tests to verify interpolation behavior and slicing functionality.
  • Bug Fixes

    • Updated logic to prevent duplicate shapes during interpolation.
  • Tests

    • Increased test coverage for TrackManager and AnnotationIR classes, including new test methods and classes.
  • Chores

    • Updated formatting script to include additional test files for consistent code styling.

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes encompass modifications to the AnnotationIR and TrackManager classes in the cvat/apps/dataset_manager/annotation.py file, enhancing methods for filtering and interpolating shapes. Additionally, the test_annotation.py file has been updated to improve test coverage, including new tests and consistent formatting. The dev/format_python_code.sh script has been adjusted to include a new path for formatting the test file. Overall, these updates refine annotation management and testing processes.

Changes

File Path Change Summary
cvat/apps/dataset_manager/annotation.py - Enhanced _slice_track method in AnnotationIR for valid shape inclusion.
- Modified slice method for shape and track filtering.
- Updated get_interpolated_shapes in TrackManager to prevent duplicate shapes.
- Method signature changed for get_interpolated_shapes.
cvat/apps/dataset_manager/tests/test_annotation.py - Updated string delimiters in TrackManagerTest methods.
- Added test_duplicated_shape_interpolation to verify interpolation behavior.
- Introduced AnnotationIRTest class with test_slice_track_does_not_duplicate_outside_frame_on_the_end method.
dev/format_python_code.sh - Added path for formatting cvat/apps/dataset_manager/tests/test_annotation.py.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AnnotationIR
    participant TrackManager

    User->>AnnotationIR: Request to slice track
    AnnotationIR->>AnnotationIR: Validate shapes
    AnnotationIR->>TrackManager: Request interpolated shapes
    TrackManager->>TrackManager: Check for duplicates
    TrackManager-->>AnnotationIR: Return valid shapes
    AnnotationIR-->>User: Return sliced track
Loading

🐰 In the code, we hop and play,
With shapes and tracks, we find our way.
Tests are added, code is neat,
In the garden of logic, we dance on our feet!
🥕


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.

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

🧹 Outside diff range and nitpick comments (3)
dev/format_python_code.sh (1)

33-33: LGTM! Consider grouping related paths for better maintainability.

The addition of "cvat/apps/dataset_manager/tests/test_annotation.py" to the list of paths for formatting is appropriate and aligns with the goal of maintaining consistent code style across the project.

For improved maintainability, consider grouping related paths together. For example, you could move this new test file path next to other test-related paths or create a new group for dataset manager related files. This would make it easier to manage and update the list of paths in the future.

cvat/apps/dataset_manager/tests/test_annotation.py (2)

329-373: LGTM: New test case for handling duplicated shapes.

The new test_duplicated_shape_interpolation method is a valuable addition to the test suite. It verifies that the TrackManager.get_interpolated_shapes method correctly handles tracks with duplicated shapes, which is an important edge case to consider.

Suggestion for improvement:
Consider adding an assertion to verify that the outside property is correctly maintained in the interpolated shapes. This would ensure that the interpolation not only removes duplicates but also preserves the correct state of each shape.

You could add the following assertion after line 373:

self.assertEqual([shape['outside'] for shape in expected_shapes], 
                 [shape['outside'] for shape in interpolated_shapes])

This will verify that the outside property is correctly maintained in the interpolated shapes.


376-425: LGTM: New test class for AnnotationIR slicing functionality.

The new AnnotationIRTest class and its test method test_slice_track_does_not_duplicate_outside_frame_on_the_end are valuable additions to the test suite. They verify important behavior of the AnnotationIR.slice method, ensuring that it correctly handles tracks with outside frames at the end.

Suggestion for improvement:
Consider adding more test cases to cover different scenarios, such as:

  1. Slicing a track with multiple outside frames in the middle.
  2. Slicing a track where the slice end is beyond the last frame of the track.

You could add these additional test methods to provide more comprehensive coverage:

def test_slice_track_with_multiple_outside_frames(self):
    # Add test case for slicing a track with multiple outside frames in the middle

def test_slice_track_beyond_last_frame(self):
    # Add test case for slicing a track where the slice end is beyond the last frame
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 49ec1d1 and 85ca560.

📒 Files selected for processing (3)
  • cvat/apps/dataset_manager/annotation.py (2 hunks)
  • cvat/apps/dataset_manager/tests/test_annotation.py (20 hunks)
  • dev/format_python_code.sh (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
cvat/apps/dataset_manager/tests/test_annotation.py (3)

7-8: LGTM: New imports added correctly.

The new imports for AnnotationIR and DimensionType are correctly added and necessary for the new test class AnnotationIRTest.


13-13: LGTM: Consistent string delimiter usage and improved dictionary formatting.

The changes improve code consistency by:

  1. Using double quotes for string literals consistently across all test methods.
  2. Adding trailing commas to the attributes field in shape dictionaries, which improves readability and makes future additions easier.

These changes align with Python best practices and improve overall code quality.

Also applies to: 28-28, 45-45, 53-53, 61-61, 82-82, 90-90, 98-98, 120-120, 129-129, 138-138, 160-160, 169-169, 178-178, 200-200, 218-219


Line range hint 1-425: Overall assessment: Improved test coverage and code consistency.

The changes in this file significantly enhance the test suite for the TrackManager and AnnotationIR classes. Key improvements include:

  1. Consistent use of string delimiters and improved dictionary formatting throughout the file.
  2. New test case for handling duplicated shapes in track interpolation.
  3. New test class for verifying the slicing functionality of AnnotationIR.

These changes will help ensure the robustness of the annotation handling code, particularly in edge cases involving duplicated shapes and track slicing. The improved consistency also enhances code readability and maintainability.

To further strengthen the test suite, consider implementing the suggested additional test cases for AnnotationIR slicing and the extra assertion for the duplicated shape test.

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

134-135: Logic for appending shapes is correct

The condition and the append operation appropriately ensure that the last shape from scoped_shapes is added to segment_shapes when necessary. This maintains the correct sequence of shapes based on frame numbers.

cvat/apps/dataset_manager/annotation.py Outdated Show resolved Hide resolved
@Eldies Eldies requested a review from nmanovic as a code owner October 17, 2024 10:00
@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.27%. Comparing base (5259603) to head (2ec6756).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8553      +/-   ##
===========================================
+ Coverage    74.25%   74.27%   +0.01%     
===========================================
  Files          403      403              
  Lines        43313    43315       +2     
  Branches      3914     3914              
===========================================
+ Hits         32163    32173      +10     
+ Misses       11150    11142       -8     
Components Coverage Δ
cvat-ui 78.74% <ø> (+0.04%) ⬆️
cvat-server 70.47% <100.00%> (+<0.01%) ⬆️

@PMazarovich
Copy link
Contributor

PMazarovich commented Oct 17, 2024

Hwllo, @Eldies
Here is the backup: https://disk.yandex.ru/d/S51OWHYeCTHDgw - it is not allowed to place here smth > 25 Mb
With this task you will be able to see annotations, but when you create a task with 3000 job size out of the same video, you export annotations and then import to the new "multijob" task, you'll see Assertion error.
Also, I've seen today this OSError: [Errno 39] Directory not empty: '/home/django/data/tasks/961282/tmp/tmpq00w8s6x' , but it is a side topic and, I think, is not critical.

@Eldies
Copy link
Contributor Author

Eldies commented Oct 18, 2024

@PMazarovich Thank you for the backup! I checked it with this PR and it seems the PR fixes the problem.

Comment on lines 954 to 955
if curr_frame == prev_shape["frame"]:
if dict(shape, id=None, keyframe=None) == dict(prev_shape, id=None, keyframe=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 if statements can be combined into one.
Why do we need to exclude keyframe when comparing shapes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They can be combined, but then this line becomes too long (137 cahracters) and should be split to 2 lines anyway, and I think it is more readable the way it is now.
keyframe should be excluded, because it is always True in prev_shape due to shape["keyframe"] = True on line 967.

Copy link
Contributor

Choose a reason for hiding this comment

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

They can be combined, but then this line becomes too long (137 cahracters) and should be split to 2 lines anyway, and I think it is more readable the way it is now.

if (
    condition1
    and condition2
):
    ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, combined them

@@ -0,0 +1,4 @@
### Fixed

- Track shape duplication on import
Copy link
Contributor

Choose a reason for hiding this comment

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

Now there should be no errors during export tracks with duplicated shapes. Why not mention that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rewritten it a bit

@Marishka17
Copy link
Contributor

@Eldies, Could you please resolve conflicts?

@Eldies
Copy link
Contributor Author

Eldies commented Oct 23, 2024

@Eldies, Could you please resolve conflicts?

resolved

@Eldies Eldies force-pushed the dl/fix-invalid-tracks branch from 5aa4e42 to 2ec6756 Compare October 23, 2024 12:48
Copy link

@Eldies Eldies merged commit d8c3042 into develop Oct 24, 2024
34 checks passed
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.

Can not export CVAT for video annotaitons
4 participants