talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
427 stars 97 forks source link

Allow inference on multiple individual videos via `sleap-track` #1777

Closed emdavis02 closed 2 months ago

emdavis02 commented 4 months ago

Discussed in https://github.com/talmolab/sleap/discussions/1439

Problem Description

Originally posted by **roomrys** August 4, 2023 Currently, to run inference on multiple videos via the `sleap-track` command, users need to call this command many times either manually or in a script. It might be a nice feature to allow multiple videos/inputs.

Feature Proposal

Implementation Details

Currently, sleap_track takes in an argument data_path from the command line that is the file path to a .slp file, this means that the user must run this function once for every video they wish to run an inference on either manually or through a script. We would like to allow the argument data_path to also take in a path to a folder of .slp files and run an inference on each of these files. This will all be acomplished in sleap/nn/inference.py

1. Create an optional flag to the cli to specify if data_path is a folder

2. Make data_path a list to enable iteration

Note: The "labels" cli argument has been deprecated and will not need to be edited to accomodate this new function. https://github.com/talmolab/sleap/blob/43a4f13ab28d2726af4a9c1858e8e2cde06d53cc/sleap/nn/inference.py#L5292-L5296

3. Add a loop to file loading lines

4. Add a loop to main() for running inference and tracking

5. Add an aditional loop to main() for just running tracking

Documentation Changes

Changes will be made to the sleap-track section of the documentation

positional arguments: data_path Path to data to predict on. This can be one of the following:

optional arguments: ... -o OUTPUT, --output OUTPUT The output filename or directory path to use for the predicted data. If not provided, defaults to '[data_path].predictions.slp'.

eberrigan commented 4 months ago

Great job @emdavis02!

talmo commented 4 months ago
  • We could try it with and without the additional argument to determine if the input is a directory. It might be sufficient to use os.path.isdir() and os.path.isfile()` documented here.

Just jumping in to say: please use pathlib instead of os.path APIs!

eberrigan commented 4 months ago

Thanks! Here is the correspondence between os.path and Path: correspondence to tools in the os module