sleap-io
Standalone utilities for working with animal pose tracking data.
This is intended to be a complement to the core SLEAP
package that aims to provide functionality for interacting with pose tracking-related
data structures and file formats with minimal dependencies. This package does not
have any functionality related to labeling, training, or inference.
Installation
pip install sleap-io
For development, use one of the following syntaxes:
conda env create -f environment.yml
pip install -e .[dev]
See CONTRIBUTING.md
for more information on development.
Usage
Load and save in different formats
import sleap_io as sio
labels = sio.load_file("predictions.slp")
sio.save_file(labels, "predictions.nwb")
Convert labels to raw arrays
import sleap_io as sio
labels = sio.load_slp("tests/data/slp/centered_pair_predictions.slp")
trx = labels.numpy()
n_frames, n_tracks, n_nodes, xy = trx.shape
assert xy == 2
trx_with_scores = labels.numpy(return_confidence=True)
n_frames, n_tracks, n_nodes, xy_score = trx.shape
assert xy_score == 3
Read video data
import sleap_io as sio
video = sio.load_video("test.mp4")
n_frames, height, width, channels = video.shape
frame = video[0]
height, width, channels = frame.shape
Create labels from raw data
import sleap_io as sio
import numpy as np
skeleton = sio.Skeleton(
nodes=["head", "thorax", "abdomen"],
edges=[("head", "thorax"), ("thorax", "abdomen")]
)
video = sio.load_video("test.mp4")
instance = sio.Instance.from_numpy(
points=np.array([
[10.2, 20.4],
[5.8, 15.1],
[0.3, 10.6],
]),
skeleton=skeleton
)
lf = sio.LabeledFrame(video=video, frame_idx=0, instances=[instance])
labels = sio.Labels(videos=[video], skeletons=[skeleton], labeled_frames=[lf])
labels.save("labels.slp")
Support
For technical inquiries specific to this package, please open an Issue
with a description of your problem or request.
For general SLEAP usage, see the main website.
Other questions? Reach out to talmo@salk.edu
.
License
This package is distributed under a BSD 3-Clause License and can be used without
restrictions. See LICENSE
for details.