Skip to content

Add SLEAP conversion example - #87

Open
lochhh wants to merge 4 commits into
mainfrom
ch/slp-example
Open

lochhh wants to merge 4 commits into
mainfrom
ch/slp-example

Conversation

@lochhh

@lochhh lochhh commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
Closes #83
Adds SLEAP project → PoseMark example, so we now cover DLC, LP, and SLEAP.

What does this PR do?
This PR

  • adds a SLEAP → PoseMark conversion example that's adapted from the DLC example.
  • adds a SLEAP project example under tests/data/sleap/MouseTopDown-EPM. The .slp files are created synthetically, based on MouseTopDown-Loukia-2022-09-13 - verified by loading the .slp files in the SLEAP GUI. The difference here is that the SLEAP labels file uses frame numbers 10, 50, 90 because the videos only have 100 frames, rather than those that are way out of the videos; the DLC data uses frame numbers >100. I've avoided naming the SLEAP data the same as for DLC for this reason. Perhaps a future PR to clean up the test fixtures, e.g. A more cohesive set of test fixtures #53 could consider unifying the datasets across different tools - this would also be useful for round-trip tests, for instance, making sure that converting the same datasets in different format results in the same PoseMark dataset.
  • additionally changes the LP example to save .lp_session files in a separate temp dir instead of storing them in the posemark base dir (for cleaner separation - in case the script crashes and never reaches the clean-up step, these session files will stay in the base dir).

References

#83

How has this PR been tested?

Docs built locally

Does this PR require an update to the documentation?

This is a documentation update

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality
  • The documentation has been updated to reflect any changes
  • The code has been formatted with pre-commit

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.99%. Comparing base (0df45e1) to head (0912253).

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #87   +/-   ##
=======================================
  Coverage   93.99%   93.99%           
=======================================
  Files           5        5           
  Lines         416      416           
=======================================
  Hits          391      391           
  Misses         25       25           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lochhh
lochhh marked this pull request as ready for review October 16, 2026 13:21
@lochhh
lochhh requested a review from a team October 19, 2026 09:05
@niksirbi

Copy link
Copy Markdown
Member

Thanks @lochhh! Happy to review this one.

@niksirbi niksirbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @lochhh. This brings as closer to being able to make a higher-level conversion API, akin to #50, but we should probably tackle #58 before we attempt that.

I've left some notes, but most of them are ideas for improvement that could be also done as follow-up. Do them in this PR or open them as issues, as you prefer.

The only issue that needs fixing is in the crash on grayscale videos (see inline comment).

I'm pre-approving this for your convenience.

Comment thread examples/convert_sleap_to_posemark.py Outdated
Comment on lines +84 to +85
# - Labeled frames are not stored as image files; they are read directly
# from the videos referenced by the labels file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is worth qualifying this statement a bit? That's true of 'standard' .slp files, but in .pkg.slp files the frames can be stored inside the file itself.

I wonder if at some point we need a helper in poseinterface.io that can take frames from a variety of sources (extracted from the video, taken from .pkg.slp, or directly as an image sequece) and write them in PoseMark format. That would also replcae the inline imegeio loop later in this example.

Not needed for this PR, but sth to keep in mind.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

and opened #88

Comment thread examples/convert_sleap_to_posemark.py Resolved
Comment on lines +175 to +188
# Extract this session's user annotations (dropping any predicted
# instances), save them to a temporary per-session labels file, and
# convert them to COCO frame labels JSON.
session_labels = labels.extract(source_video_path)
session_labels.remove_predictions()
with tempfile.TemporaryDirectory() as tmp_dir:
session_labels_path = Path(tmp_dir) / f"{source_video_path.stem}.slp"
session_labels.save(session_labels_path)
framelabels_path = annotations_to_posemark(
input_path=session_labels_path,
output_dir=target_frames_dir,
format="frame",
**ids,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Each session's labels here have to take a detour through a temporary .slp file because annotations_to_posemark only accepts a file path.

I wonder if it's possible to have it also accept a labels object loaded with sleap-io. That would remove the need for this detour.

Could be also explored in a follow-up PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

opened #89

/ "sleap"
/ "MouseTopDown-EPM"
)
print(tree(source_project_dir, level=1, exclude_hidden=True))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use level=2 to also show the predictions file names?

Suggested change
print(tree(source_project_dir, level=1, exclude_hidden=True))
print(tree(source_project_dir, level=2, exclude_hidden=True))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the 2 other examples use level=1 - should all of these use 2?

lochhh and others added 2 commits October 29, 2026 18:37

This branch has not been deployed

No deployments
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.

Add example for converting SLEAP projects

2 participants