talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
437 stars 97 forks source link

(3a -> 3) Serialize `FrameGroup` and `InstanceGroup` (update `RecordingSession` serialization) #1749

Closed roomrys closed 7 months ago

roomrys commented 7 months ago

Description

This PR aims to serialize/deserialize FrameGroups (and consequently InstanceGroups).

Types of changes

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

Thank you for contributing to SLEAP!

:heart:

Summary by CodeRabbit

coderabbitai[bot] commented 7 months ago

Walkthrough

The updates across the sleap modules enhance data handling and serialization, particularly for RecordingSession and InstanceGroup classes. New attributes and methods support more detailed management of instances and frames within sessions. Changes also streamline the interaction with JSON files, improving the robustness and clarity of the codebase.

Changes

Files Change Summary
.../io/cameras.py Extended InstanceGroup and RecordingSession with new attributes and methods for better data management. Added serialization capabilities to FrameGroup.
.../io/dataset.py Updated to_dict method to include sessions key and enhanced handling of labeled frames.
.../io/format/labels_json.py Modified comments for clarity and restructured session loading logic based on JSON content.
.../io/test_cameras.py Updated tests to reflect changes in RecordingSession and InstanceGroup, including new dictionary handling methods.

πŸ‡βœ¨ Oh hooray, oh hooray, the code's got its sway, New fields bloom like flowers in May. Frames and sessions dance in a line, With every commit, oh how we shine! Let’s hop with joy, for the code does deploy, In the land of SLEAP, where bugs dare not creep. 🌟 πŸ‡βœ¨


Recent Review Details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 712fc70610973251648433d723f4d557d87b56d5 and d9eafa75d1eaaf9eba330e7cad289d1f095ca09e.
Files selected for processing (4) * sleap/io/cameras.py (15 hunks) * sleap/io/dataset.py (2 hunks) * sleap/io/format/labels_json.py (4 hunks) * tests/io/test_cameras.py (9 hunks)
Additional Context Used
Ruff (29)
sleap/io/cameras.py (7)
79-79: f-string without any placeholders --- 80-80: f-string without any placeholders --- 81-81: f-string without any placeholders --- 452-452: Undefined name `Skeleton` --- 605-605: Undefined name `Skeleton` --- 832-832: Do not use bare `except` --- 1003-1003: Undefined name `Labels`
sleap/io/dataset.py (16)
55-55: Redefinition of unused `Callable` from line 45 --- 61-61: `h5py` imported but unused --- 69-69: Do not use bare `except` --- 70-70: `typing._ForwardRef` imported but unused --- 365-365: Do not assign a `lambda` expression, use a `def` --- 367-370: Do not assign a `lambda` expression, use a `def` --- 372-375: Do not assign a `lambda` expression, use a `def` --- 934-934: Do not compare types, use `isinstance()` --- 1454-1454: Do not compare types, use `isinstance()` --- 2360-2360: Undefined name `glob` --- 2455-2455: Avoid equality comparisons to `False`; use `if not ret:` for false checks --- 2543-2543: Avoid equality comparisons to `False`; use `if not ret:` for false checks --- 2558-2558: Undefined name `sleap` --- 2648-2648: Do not compare types, use `isinstance()` --- 2651-2651: Local variable `e` is assigned to but never used --- 2653-2653: f-string without any placeholders
sleap/io/format/labels_json.py (6)
159-159: Local variable `ex` is assigned to but never used --- 229-229: Local variable `ex` is assigned to but never used --- 385-385: Do not compare types, use `isinstance()` --- 410-410: Do not use bare `except` --- 414-414: Do not use bare `except` --- 434-434: Local variable `new_skel` is assigned to but never used
Additional comments not posted (11)
tests/io/test_cameras.py (8)
`138-138`: Ensure the new parameter `multiview_min_session_labels` is properly integrated and used within the test function. --- `216-224`: The method `to_session_dict` has been updated to include `labeled_frame_to_idx`. Verify that this change integrates well with the existing logic and that all dependencies are correctly handled. --- `241-246`: The method `from_session_dict` now includes `labeled_frames_list`. Ensure that this addition is compatible with the existing deserialization logic and that all related data structures are correctly updated. --- `267-272`: The `make_cattr` method has been enhanced to handle `labeled_frames_list` and `labeled_frame_to_idx`. Confirm that these changes are correctly implemented and that they do not introduce any regressions. --- `378-378`: The method `from_instance_by_camcorder_dict` has been updated. Ensure that the changes are correctly implemented and that they integrate well with the existing logic. --- `396-404`: The `to_dict` method in the `InstanceGroup` class has been updated to handle `instance_to_lf_and_inst_idx`. Verify that this change integrates well with the existing logic and that all dependencies are correctly handled. --- `521-530`: The `to_dict` method in the `FrameGroup` class has been updated to handle `labeled_frame_to_idx`. Verify that this change integrates well with the existing logic and that all dependencies are correctly handled. --- `531-536`: The `from_dict` method now includes `labeled_frames_list`. Ensure that this addition is compatible with the existing deserialization logic and that all related data structures are correctly updated.
sleap/io/format/labels_json.py (3)
`392-392`: Update the comment for clarity and consistency. Consider changing to "Don't break if the JSON doesn't include tracks." --- `417-417`: Update the comment for clarity and consistency. Consider changing to "If we're given a Labels object to match, use its objects when they match." --- `540-555`: Verify the restructuring of code related to loading `RecordingSession`s based on the presence of "sessions" in the input data. Ensure that this change integrates well with the existing logic and that all dependencies are correctly handled.
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 7 months ago

Codecov Report

Attention: Patch coverage is 72.22222% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 73.35%. Comparing base (712fc70) to head (d9eafa7).

Files Patch % Lines
sleap/io/cameras.py 73.07% 21 Missing :warning:
sleap/io/format/labels_json.py 55.55% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## liezl/asc-initial-update-instances-across-views #1749 +/- ## ================================================================================ Coverage 73.34% 73.35% ================================================================================ Files 135 135 Lines 24821 24875 +54 ================================================================================ + Hits 18205 18247 +42 - Misses 6616 6628 +12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.