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

Labels QOL enhancements #81

Merged
merged 16 commits into from
Apr 14, 2024
Merged

Labels QOL enhancements #81

merged 16 commits into from
Apr 14, 2024

Conversation

talmo
Copy link
Contributor

@talmo talmo commented Apr 14, 2024

  • LabeledFrame.remove_predictions: Remove predicted instances from a labeled frame.
  • LabeledFrame.remove_empty_instances: Remove instances with no visible points from a labeled frame.
  • Labels.save: Instance-level convenience wrapper for sio.save_file.
  • Labels.clean: Remove unused or empty frames, instances, videos, skeletons and tracks.
  • Labels.remove_predictions: Remove predicted instances from all labeled frames (Remove predictions from labels #69).
  • Labels.__getitem__: Now supports lists, slices, numpy arrays, tuples of (Video, frame_idx) and Video.

Summary by CodeRabbit

  • New Features
    • Enhanced the LabeledFrame class with methods to remove specific predictions and empty instances.
    • Improved label indexing support and added methods for saving and cleaning labels.
  • Tests
    • Added new test functions to validate the removal of predictions and empty instances from LabeledFrame.
    • Implemented comprehensive testing for new label functionalities.

Copy link
Contributor

coderabbitai bot commented Apr 14, 2024

Walkthrough

The recent updates bring significant enhancements to data management in the LabeledFrame and Labels classes. These changes introduce new methods for removing predictions and empty instances, improving indexing support, enabling label saving in different formats, and enhancing data cleaning capabilities. The addition of comprehensive tests ensures the robustness and reliability of these new features, promoting efficient data handling for machine learning tasks.

Changes

File Path Change Summary
.../model/labeled_frame.py Added methods remove_predictions and remove_empty_instances to LabeledFrame.
.../model/labels.py Enhanced __getitem__, added save and clean methods, and included remove_predictions for label management.
.../tests/model/test_labeled_frame.py Added tests for new methods in LabeledFrame to ensure functionality.
.../tests/model/test_labels.py Expanded tests to cover new features in Labels, including various clean operations and label saving.
.github/workflows/ci.yml Set a timeout-minutes of 15 for the tests job in the workflow configuration.
.../__init__.py Added save_file function to the list of exported functions.

Poem

🐇✨
In the realm of code and frame,
A rabbit hopped, its improvements became.
Data cleaned with a magical air,
Predictions vanish, with utmost care.
Datasets now shine and gleam,
Thanks to the rabbit's dreamy scheme!
🌟📊


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5a5892d and 2492e71.
Files selected for processing (1)
  • sleap_io/init.py (1 hunks)
Additional comments not posted (1)
sleap_io/__init__.py (1)

29-29: Added save_file to the list of exported functions.

This addition aligns with the PR's objective to enhance data handling capabilities in the software.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

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

Comment on lines +66 to +86
elif type(key) == slice:
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))]
elif type(key) == list:
return [self.labeled_frames[i] for i in key]
elif isinstance(key, np.ndarray):
return [self.labeled_frames[i] for i in key.tolist()]
elif type(key) == tuple and len(key) == 2:
video, frame_idx = key
res = self.find(video, frame_idx)
if len(res) == 1:
return res[0]
elif len(res) == 0:
raise IndexError(
f"No labeled frames found for video {video} and "
f"frame index {frame_idx}."
)
elif type(key) == Video:
res = self.find(key)
if len(res) == 0:
raise IndexError(f"No labeled frames found for video {key}.")
return res
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using isinstance() for type checking instead of direct type comparison. This is more Pythonic and supports inheritance.

- elif type(key) == slice:
+ elif isinstance(key, slice):
- elif type(key) == list:
+ elif isinstance(key, list):
- elif type(key) == tuple and len(key) == 2:
+ elif isinstance(key, tuple) and len(key) == 2:
- elif type(key) == Video:
+ elif isinstance(key, Video):

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
elif type(key) == slice:
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))]
elif type(key) == list:
return [self.labeled_frames[i] for i in key]
elif isinstance(key, np.ndarray):
return [self.labeled_frames[i] for i in key.tolist()]
elif type(key) == tuple and len(key) == 2:
video, frame_idx = key
res = self.find(video, frame_idx)
if len(res) == 1:
return res[0]
elif len(res) == 0:
raise IndexError(
f"No labeled frames found for video {video} and "
f"frame index {frame_idx}."
)
elif type(key) == Video:
res = self.find(key)
if len(res) == 0:
raise IndexError(f"No labeled frames found for video {key}.")
return res
elif isinstance(key, slice):
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))]
elif isinstance(key, list):
return [self.labeled_frames[i] for i in key]
elif isinstance(key, np.ndarray):
return [self.labeled_frames[i] for i in key.tolist()]
elif isinstance(key, tuple) and len(key) == 2:
video, frame_idx = key
res = self.find(video, frame_idx)
if len(res) == 1:
return res[0]
elif len(res) == 0:
raise IndexError(
f"No labeled frames found for video {video} and "
f"frame index {frame_idx}."
)
elif isinstance(key, Video):
res = self.find(key)
if len(res) == 0:
raise IndexError(f"No labeled frames found for video {key}.")
return res

Copy link

codecov bot commented Apr 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.33%. Comparing base (599b207) to head (2492e71).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #81      +/-   ##
==========================================
+ Coverage   95.16%   95.33%   +0.17%     
==========================================
  Files          13       13              
  Lines        1551     1609      +58     
==========================================
+ Hits         1476     1534      +58     
  Misses         75       75              

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

@talmo talmo linked an issue Apr 14, 2024 that may be closed by this pull request
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

Comment on lines 26 to 30
save_jabs,
load_video,
load_file,
save_file,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [7-28]

Consider addressing the unused imports.

Many imports in this file are flagged as unused. If these are meant to be available for external use, add them to the __all__ list to explicitly export them. Otherwise, consider removing them to clean up the codebase. Here's an example of how you might modify the code:

- from sleap_io.model.skeleton import Node, Edge, Skeleton, Symmetry
- from sleap_io.model.video import Video
- from sleap_io.model.instance import (
-     Point,
-     PredictedPoint,
-     Track,
-     Instance,
-     PredictedInstance,
- )
- from sleap_io.model.labeled_frame import LabeledFrame
- from sleap_io.model.labels import Labels
- from sleap_io.io.main import (
-     load_slp,
-     save_slp,
-     load_nwb,
-     save_nwb,
-     load_labelstudio,
-     save_labelstudio,
-     load_jabs,
-     save_jabs,
-     load_video,
-     load_file,
-     save_file,
- )
+ __all__ = ['Node', 'Edge', 'Skeleton', 'Symmetry', 'Video', 'Point', 'PredictedPoint', 'Track', 'Instance', 'PredictedInstance', 'LabeledFrame', 'Labels', 'load_slp', 'save_slp', 'load_nwb', 'save_nwb', 'load_labelstudio', 'save_labelstudio', 'load_jabs', 'save_jabs', 'load_video', 'load_file', 'save_file']

@talmo talmo merged commit 0035e86 into main Apr 14, 2024
9 checks passed
@talmo talmo deleted the talmo/labels-qol branch April 14, 2024 06:22
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.

Remove predictions from labels
1 participant