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

Save .slp file after inference #135

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sleap_nn/inference/predictors.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def predict(
# Create SLEAP data structures from the predictions.
pred_labels = self._make_labeled_frames_from_generator(generator)
if save_path:
sio.io.slp.write_labels(save_path, pred_labels)
pred_labels.save(Path(save_path).as_posix())
return pred_labels

else:
Expand Down
2 changes: 2 additions & 0 deletions sleap_nn/training/model_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ def __init__(
else:
self.crop_hw = self.crop_hw[0]

OmegaConf.save(config=self.config, f=f"{self.dir_path}/training_config.yaml")

def _create_data_loaders_torch_dataset(self):
"""Create a torch DataLoader for train, validation and test sets using the data_config."""
train_labels = sio.load_slp(self.config.data_config.train_labels_path)
Expand Down
4 changes: 4 additions & 0 deletions tests/inference/test_predictors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_topdown_predictor(
minimal_instance_ckpt,
minimal_instance_centroid_ckpt,
minimal_instance_bottomup_ckpt,
tmp_path,
):
"""Test TopDownPredictor class for running inference on centroid and centered instance models."""
# for centered instance model
Expand All @@ -25,12 +26,15 @@ def test_topdown_predictor(
return_confmaps=False,
make_labels=True,
peak_threshold=0.0,
save_path=f"{tmp_path}/test.pkg.slp",
)
assert isinstance(pred_labels, sio.Labels)
assert len(pred_labels) == 1
assert len(pred_labels[0].instances) == 2
lf = pred_labels[0]

assert Path(f"{tmp_path}/test.pkg.slp").exists

# check if the predicted labels have same video and skeleton as the ground truth labels
gt_labels = sio.load_slp(minimal_instance)
gt_lf = gt_labels[0]
Expand Down