Loading and saving keypoint annotation- SLEAP Integration.#135
Open
HarshdipSaha wants to merge 19 commits into
Open
Loading and saving keypoint annotation- SLEAP Integration.#135HarshdipSaha wants to merge 19 commits into
HarshdipSaha wants to merge 19 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
- Coverage 99.45% 99.33% -0.13%
==========================================
Files 8 11 +3
Lines 554 903 +349
==========================================
+ Hits 551 897 +346
- Misses 3 6 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Hi @HarshdipSaha, would you mind having a look at the CI checks and solving the relevant issues? Thanks! |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Author
|
Hi @sfmig , I have added the relevant tests for load and save key points |
Signed-off-by: Harshdip Saha <141698575+HARSHDIPSAHA@users.noreply.github.com>
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add keypoint annotations support
Description
What is this PR
Why is this PR needed?
This PR addresses #112 by adding support for loading and saving keypoint annotations datasets. Currently, ethology only supports bounding box annotations, but many pose estimation workflows (e.g., using SLEAP) work with keypoint data. This feature extends ethology's capabilities to handle keypoint annotations while maintaining consistency with the existing bounding box implementation.
What does this PR do?
This PR implements keypoint annotations support following the same architectural patterns as bounding boxes:
Validator: Adds
ValidKeypointsAnnotationsDatasetclass inethology/validators/annotations.pythat validates datasets with required dimensions(image_id, space, keypoint, id)and required data variableposition.Loader: Adds
ethology/io/annotations/load_keypoints.pywithfrom_files()function that:sleap-ioto load SLEAP.slpfilesLabelsobjects into ethology's 4D xarray formatSaver: Adds
ethology/io/annotations/save_keypoints.pywithto_file()function that:Labelsobjectssleap-ioto save to.slpformatIntegration: Updates
ethology/io/annotations/__init__.pyto export the new modules.Dependencies: Adds
sleap-ioas an optional dependency (required only for keypoints IO).Tests: Adds comprehensive validator tests in
tests/test_unit/test_validators/test_annotations.pyand test fixtures intests/fixtures/annotations.py.The implementation follows ethology's design principles:
idin different images don't refer to the same individual)iddimension ranges from 0 to maximum number of instances per imageReferences
Closes #112
How has this PR been tested?
Unit tests: Added 6 test cases for
ValidKeypointsAnnotationsDatasetvalidator covering valid datasets, invalid datasets (missing dimensions/variables), and edge cases. All tests pass.Integration tests: Created synthetic SLEAP files and verified:
(image_id, space, keypoint, id)Manual testing: Tested with synthetic data showing:
Correct handling of empty first frames (fixed bug where code would crash if frame 0 had no instances)
Proper NaN handling for occluded keypoints
Visualization of 4D hypercube structure
Existing tests: All existing bounding box tests continue to pass, confirming no regressions.
Is this a breaking change?
No..
Does this PR require an update to the documentation?
Yes, documentation can be updated to:
load_keypointsandsave_keypointsmodules in the API referencesleap-ioas an optional dependency for keypoints supportChecklist:
Additional Notes
The validator is located in
ethology/validators/annotations.py(notethology/io/annotations/validate.py) to match the existing codebase structure where all validators are in thevalidatorsmodule.The implementation includes defensive code to handle variations in sleap-io API (different attribute names, optional parameters) to ensure compatibility across sleap-io versions.