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

ignore deleted frames when converting tracks to shapes #8834

Merged
merged 4 commits into from
Dec 18, 2024

Conversation

Eldies
Copy link
Contributor

@Eldies Eldies commented Dec 16, 2024

Motivation and context

When a frame which contains a keyframe of a track is deleted, the keyframe continues to exist. When a dataset is exported (in all formats except CVAT for video), tracks are interpolated and keyframe from deleted frame is not ignored.
Fixing it.

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 shape management by allowing exclusion of shapes based on deleted frames in both AnnotationManager and TrackManager.
    • Introduced a method for deleting specified frames from job data and verifying the integrity of subsequent annotations in tests.
  • Bug Fixes

    • Improved handling of deleted frames by transitioning from a dictionary to a set for better performance and clarity.
  • Tests

    • Added tests to ensure frame deletion functionality works as intended without affecting subsequent annotations.

@Eldies Eldies requested a review from zhiltsov-max as a code owner December 16, 2024 16:53
Copy link
Contributor

coderabbitai bot commented Dec 16, 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 changes primarily focus on enhancing frame deletion handling across the CVAT dataset management system. The modifications introduce a new deleted_frames parameter to shape-related methods in annotation and binding classes, allowing more precise control over frame processing. The implementation shifts from using dictionaries to sets for deleted frames, simplifying data structures and improving performance. Additionally, new test methods have been added to verify the behavior of annotations when frames are deleted.

Changes

File Change Summary
cvat/apps/dataset_manager/annotation.py - Updated AnnotationManager.to_shapes() method signature to include deleted_frames parameter
- Updated TrackManager.to_shapes() method signature to include deleted_frames parameter
- Modified import from Optional to Collection for type hinting
cvat/apps/dataset_manager/bindings.py - Changed _deleted_frames initialization from dictionary to set
- Updated deleted_frames property to explicitly return set[int]
- Modified group_by_frame method to pass deleted_frames parameter
cvat/apps/dataset_manager/tests/test_formats.py - Added _delete_job_frames() method to delete specific job frames
- Added test_track_keyframes_on_deleted_frames_do_not_affect_later_frames() test method

Sequence Diagram

sequenceDiagram
    participant User
    participant AnnotationManager
    participant TrackManager
    
    User->>AnnotationManager: to_shapes(end_frame, deleted_frames)
    AnnotationManager-->>User: Filtered shapes excluding deleted frames
    
    User->>TrackManager: to_shapes(end_frame, deleted_frames)
    TrackManager-->>User: Filtered shapes excluding deleted frames
Loading

Poem

🐰 Frames dance, some take their leave,
Annotations stay, they won't deceive
Sets replace the old dict's might
Deleted frames now filtered bright
Code hops forward with rabbit's glee! 🚀


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

🧹 Nitpick comments (1)
cvat/apps/dataset_manager/tests/test_formats.py (1)

534-589: LGTM: Comprehensive test for deleted frame handling

The test effectively verifies that keyframes on deleted frames don't affect interpolation. Consider adding edge cases:

  • Multiple consecutive deleted frames
  • Deleted frames at track boundaries
def test_track_keyframes_on_multiple_deleted_frames_do_not_affect_later_frames(self):
    images = self._generate_task_images(5)
    task = self._generate_task(images)
    job = self._get_task_jobs(task["id"])[0]

    annotations = {
        "version": 0,
        "tags": [],
        "shapes": [],
        "tracks": [{
            "frame": 0,
            "label_id": task["labels"][0]["id"],
            "group": None,
            "source": "manual",
            "attributes": [],
            "shapes": [
                {
                    "frame": 0,
                    "points": [1, 2, 3, 4],
                    "type": "rectangle",
                    "occluded": False,
                    "outside": False,
                    "attributes": [],
                },
                {
                    "frame": 1,
                    "points": [5, 6, 7, 8],
                    "type": "rectangle",
                    "occluded": False,
                    "outside": False,
                    "attributes": [],
                },
                {
                    "frame": 2,
                    "points": [9, 10, 11, 12],
                    "type": "rectangle",
                    "occluded": False,
                    "outside": False,
                    "attributes": [],
                },
                {
                    "frame": 4,
                    "points": [13, 14, 15, 16],
                    "type": "rectangle",
                    "occluded": False,
                    "outside": False,
                    "attributes": [],
                }
            ]
        }]
    }
    self._put_api_v2_job_id_annotations(job["id"], annotations)
    # Delete two consecutive frames
    self._delete_job_frames(job["id"], [1, 2])

    task_ann = TaskAnnotation(task["id"])
    task_ann.init_from_db()
    task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task["id"]))
    extractor = CvatTaskOrJobDataExtractor(task_data)
    dm_dataset = Dataset.from_extractors(extractor)

    # Verify frame 4 is not affected
    assert len(dm_dataset.get("image_4").annotations) == 1
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bf6469e and f91055c.

📒 Files selected for processing (3)
  • cvat/apps/dataset_manager/annotation.py (3 hunks)
  • cvat/apps/dataset_manager/bindings.py (5 hunks)
  • cvat/apps/dataset_manager/tests/test_formats.py (4 hunks)
🔇 Additional comments (4)
cvat/apps/dataset_manager/tests/test_formats.py (1)

525-533: LGTM: Well-structured helper method for frame deletion

The method is focused, uses appropriate HTTP semantics, and includes error checking.

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

202-222: LGTM: Clean addition of deleted frames filtering

The change is minimal, focused, and maintains backward compatibility.


470-482: LGTM: Efficient implementation of shape filtering

The implementation efficiently filters out shapes from deleted frames while preserving the track structure.

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

323-323: LGTM: Improved data structure for deleted frames

Changed from dict to set for better performance in membership testing operations.

@Eldies Eldies force-pushed the dl/deleted-track-keyframe branch from f91055c to 11eacbc Compare December 16, 2024 16:58
@Eldies Eldies changed the title ignore deleted frames when interpolating tracks ignore deleted frames when converting tracks to shapes Dec 16, 2024
@Eldies Eldies requested a review from nmanovic as a code owner December 16, 2024 17:14
@Eldies Eldies force-pushed the dl/deleted-track-keyframe branch from 91431e1 to 4535f5d Compare December 16, 2024 17:14
@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.91%. Comparing base (289ad43) to head (9cab443).
Report is 6 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8834      +/-   ##
===========================================
- Coverage    73.93%   73.91%   -0.02%     
===========================================
  Files          409      409              
  Lines        43930    43932       +2     
  Branches      3986     3986              
===========================================
- Hits         32478    32471       -7     
- Misses       11452    11461       +9     
Components Coverage Δ
cvat-ui 78.38% <ø> (+0.04%) ⬆️
cvat-server 70.08% <100.00%> (-0.08%) ⬇️

@Eldies Eldies force-pushed the dl/deleted-track-keyframe branch 2 times, most recently from b506ae7 to 6bdee91 Compare December 18, 2024 08:39
@Eldies Eldies force-pushed the dl/deleted-track-keyframe branch from 6bdee91 to eb3ce13 Compare December 18, 2024 08:40
@zhiltsov-max
Copy link
Contributor

@bsekachev, do you know if the previous behavior about the interpolation on deleted frames was intentional?

@zhiltsov-max zhiltsov-max merged commit 851fb7d into develop Dec 18, 2024
35 checks passed
@zhiltsov-max zhiltsov-max deleted the dl/deleted-track-keyframe branch December 18, 2024 13:35
@Eldies Eldies mentioned this pull request Dec 19, 2024
2 tasks
@cvat-bot cvat-bot bot mentioned this pull request Dec 20, 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