Commit 5ec062b
Append video name to output path when video_index is specified (#378)
## Summary
Fixes an issue where running inference with `video_index` on multiple
videos from the same .slp file would overwrite the output file. The
output path now includes the video name to create unique filenames for
each video.
## Problem
When running predictions on a multi-video .slp file using the
`video_index` parameter:
- All predictions would save to the same output path (e.g.,
`labels.predictions.slp`)
- Running inference on different videos would overwrite previous results
- Users had to manually specify unique `output_path` for each video
## Solution
When `video_index` is provided and `output_path` is None:
- Extract the video filename from `output.videos[video_index]`
- Append the video name (stem) to the output path
- Format: `<labels_file>.<video_name>.predictions.slp`
- Falls back to `video_{index}` if filename is not a simple string
## Example
**Before:**
```python
run_inference(data_path="labels.slp", video_index=0) # → labels.predictions.slp
run_inference(data_path="labels.slp", video_index=1) # → labels.predictions.slp (overwrites!)
```
**After:**
```python
run_inference(data_path="labels.slp", video_index=0) # video1.mp4 → labels.video1.predictions.slp
run_inference(data_path="labels.slp", video_index=1) # video2.mp4 → labels.video2.predictions.slp
```
## Changes
- Modified `run_inference()` in `sleap_nn/predict.py` to append video
name when `video_index` is specified
- Added `test_video_index_output_path()` test to verify the behavior
## Testing
- New test verifies video name is included in output path when using
video_index
- Existing tests continue to pass (no breaking changes)
- Behavior unchanged when video_index is None or output_path is
explicitly provided
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Claude <[email protected]>1 parent 558e0a9 commit 5ec062b
2 files changed
+55
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
504 | 504 | | |
505 | 505 | | |
506 | 506 | | |
507 | | - | |
508 | | - | |
509 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
510 | 524 | | |
511 | 525 | | |
512 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1423 | 1423 | | |
1424 | 1424 | | |
1425 | 1425 | | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
0 commit comments