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 track only PredictedInstance #2028

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

Conversation

getzze
Copy link
Contributor

@getzze getzze commented Nov 20, 2024

Description

Force to track only PredictedInstance and not Instance, otherwise we get an error because update_matched_instance_tracks only works PredictedInstance.
This can happen if running tracking_only with a dataset that has predicted instances from inference and user-defined instances used for training.

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

  • New Features

    • Introduced a new method to enhance tracking functionality, allowing for improved inference of the next timestep.
    • Added a parameter to control whether only predicted instances are processed during inference tasks.
    • Implemented a function to convert instances to predicted instances, improving instance management.
  • Bug Fixes

    • Streamlined the process of determining the current timestep, enhancing clarity and efficiency in tracking.
    • Minor adjustments made to the COCO dataset reading process, ensuring consistent handling of keypoints without affecting functionality.

Copy link

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in the pull request enhance the tracking functionality within the sleap/nn/tracking.py file by introducing a new method, infer_next_timestep, to the Tracker class, which simplifies the determination of the next timestep. The track method has been updated to utilize this new method, improving readability. Additionally, the run_tracker function has been modified to filter instances specifically for PredictedInstance, reflecting a shift towards handling these instances more explicitly. Similar modifications were made in the sleap/gui/learning/runners.py and sleap/instance.py files to support these changes.

Changes

File Change Summary
sleap/nn/tracking.py - Added infer_next_timestep method to Tracker class.
- Updated track method to use infer_next_timestep, simplifying logic for determining current timestep.
- Introduced only_predicted_instances attribute to Tracker class.
- Adjusted run_tracker to filter instances based on only_predicted_instances.
- Updated import statements to include convert_to_predicted_instance.
sleap/gui/learning/runners.py - Added tracking.only_predicted_instances parameter to InferenceTask class.
- Updated make_predict_cli_call method to include new parameter in CLI arguments.
- Modified run_gui_inference to accommodate changes in inference task management.
sleap/instance.py - Added convert_to_predicted_instance function for converting instances.
- Modified make_instance_cattr function to handle serialization hooks for instances.
- Updated InstancesList class to enforce type constraints on contained objects.

Possibly related PRs

  • Add normalized_instance_similarity method  #1939: The changes in this PR involve the addition of a new similarity method, normalized_instance_similarity, which is directly related to the modifications in the sleap/nn/tracking.py file where the tracking functionality is enhanced to utilize normalized keypoints based on image dimensions.

Suggested reviewers

  • talmo
  • roomrys

Poem

In the code where bunnies hop,
A new method helps us stop,
To track the time with ease and grace,
Filtering instances in their place.
With each change, we leap and bound,
In the world of code, joy is found! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c9862f2 and 54ab312.

📒 Files selected for processing (1)
  • sleap/io/format/coco.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sleap/io/format/coco.py

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

codecov bot commented Nov 20, 2024

Codecov Report

Attention: Patch coverage is 74.19355% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.47%. Comparing base (7ed1229) to head (54ab312).
Report is 58 commits behind head on develop.

Files with missing lines Patch % Lines
sleap/instance.py 14.28% 6 Missing ⚠️
sleap/io/format/coco.py 0.00% 1 Missing ⚠️
sleap/nn/tracking.py 95.65% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2028      +/-   ##
===========================================
+ Coverage    73.30%   75.47%   +2.16%     
===========================================
  Files          134      133       -1     
  Lines        24087    24654     +567     
===========================================
+ Hits         17658    18607     +949     
+ Misses        6429     6047     -382     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@getzze getzze force-pushed the fix-track-predicted-instances branch from c430585 to a520942 Compare November 26, 2024 12:19
sleap/nn/tracking.py Outdated Show resolved Hide resolved
@talmo
Copy link
Collaborator

talmo commented Dec 6, 2024

Thanks @getzze! This looks like a useful filter, but we do sometimes have use cases where we want to reuse the user-labeled instances, for example, when correcting poses or tracking the same videos you label on.

If we can put this behind a feature flag so it's optional (and add some tests), happy to approve!

Thanks for the contribution!

@getzze
Copy link
Contributor Author

getzze commented Dec 6, 2024

Thanks for reviewing! I will add an option to convert Instances to PredictedInstances before tracking.

@getzze getzze force-pushed the fix-track-predicted-instances branch from b9471f7 to c9862f2 Compare December 6, 2024 14:08
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: 0

🧹 Outside diff range and nitpick comments (1)
sleap/nn/tracking.py (1)

644-665: LGTM: Extracted timestep inference logic into a separate method.

Good refactoring to move the timestep inference logic from the track method into a dedicated method. This improves code organization and reusability.

Consider adding docstring examples to illustrate the different cases:

def infer_next_timestep(self, t: Optional[int] = None) -> int:
    """Infer timestep if not provided.
    
    Examples:
        >>> tracker = Tracker()
        >>> tracker.infer_next_timestep(5)  # Explicit timestep
        5
        >>> tracker.infer_next_timestep()  # No queue, default to 0
        0
        >>> # With queue, increment from last timestep
        >>> tracker.track_matching_queue[-1].t = 10
        >>> tracker.infer_next_timestep()
        11
    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a520942 and c9862f2.

📒 Files selected for processing (3)
  • sleap/gui/learning/runners.py (1 hunks)
  • sleap/instance.py (1 hunks)
  • sleap/nn/tracking.py (10 hunks)
🔇 Additional comments (4)
sleap/gui/learning/runners.py (1)

264-264: LGTM: Added tracking.only_predicted_instances to boolean conversion list.

The addition of tracking.only_predicted_instances to the bool_items_as_ints list ensures proper CLI argument handling for the new tracking option.

sleap/nn/tracking.py (2)

584-584: LGTM: Added only_predicted_instances attribute.

The new attribute with default value True aligns with the PR objective to track only predicted instances by default.


1528-1532: LGTM: Added conditional instance selection based on only_predicted_instances.

The implementation correctly handles both cases:

  • When only_predicted_instances is True: Uses only predicted instances
  • When only_predicted_instances is False: Converts all instances to predicted instances

This aligns with the PR objectives and the feedback from talmo about supporting both use cases.

sleap/instance.py (1)

1180-1196: LGTM: Added convert_to_predicted_instance function.

Well-implemented utility function that:

  • Handles both Instance and PredictedInstance types
  • Preserves existing PredictedInstance objects
  • Sets reasonable defaults for score (1.0) and tracking_score (0.0)
  • Reuses existing attributes through attr.asdict for clean conversion

@getzze
Copy link
Contributor Author

getzze commented Dec 10, 2024

I made the proposed changes. One test is failing for no particular reason (it should pass if re-run).

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