-
Notifications
You must be signed in to change notification settings - Fork 10
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
Ability to save multi-animal pose tracks to single-animal files #39
Labels
enhancement
New optional feature
Comments
Rough plan on how this could be doneThe current def to_dlc_file(ds: xr.Dataset, file_path: Union[str, Path]) -> None:
"""Save the xarray dataset containing pose tracks to a
DeepLabCut-style ".h5" or ".csv" file.
Parameters
----------
ds : xarray Dataset
Dataset containing pose tracks, confidence scores, and metadata.
file_path : pathlib Path or str
Path to the file to save the DLC poses to. The file extension
must be either ".h5" (recommended) or ".csv".
See Also
--------
to_dlc_df : Convert an xarray dataset containing pose tracks into a
DeepLabCut-style pandas DataFrame with multi-index columns.
""" could be changed to something like: def to_dlc_file(
ds: xr.Dataset,
file_path: Union[str, Path],
format: Literal["auto", "multi", "single"] = "auto",
) -> None:
"""Save the xarray dataset containing pose tracks to a
DeepLabCut-style ".h5" or ".csv" file.
Parameters
----------
ds : xarray Dataset
Dataset containing pose tracks, confidence scores, and metadata.
file_path : pathlib Path or str
Path to the file to save the DLC poses to. The file extension
must be either ".h5" (recommended) or ".csv".
format : {"multi", "single"}, optional
Format of the DeepLabcut output file.
- If "multi", the file will be formatted as in a multi-animal
DeepLabCut project: the columns will include the
"individuals" level and all individuals will be saved to the same file.
- If "single", the file will be formatted as in a single-animal
DeepLabCut project: no "individuals" level, and each individual will be
saved in a separate file. The individual's name will be appended to the
file path, just before the file extension, i.e.
"/path/to/filename_individual1.h5".
- If "auto" the format will be determined based on the number of
individuals in the dataset: "multi" if there are more than one, and
"single" if there is only one. This is the default.
See Also
--------
to_dlc_df : Convert an xarray dataset containing pose tracks into a
DeepLabCut-style pandas DataFrame with multi-index columns.
Examples
--------
>>> from movement.io import save_poses, load_poses
>>> ds = load_poses.from_sleap("/path/to/file_sleap.analysis.h5")
>>> save_poses.to_dlc_file(ds, "/path/to/file_dlc.h5")
""" The For reference, this how DeepLabCut itself converts between the two formats. |
7 tasks
7 tasks
7 tasks
7 tasks
github-project-automation
bot
moved this from 🚧 In Progress
to ✅ Done
in movement progress tracker
Nov 16, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is especially relevant for DeepLabCut. Its pose estimation data used to be stored in a DataFrame with the following column levels: "scorer", "bodyparts" and "coords". After the introduction of multi-animal DeepLabCut, they've added an extra "individuals" level between "scorer" and "bodyparts".
PR #33 introduced the
save_poses.to_dlc_file()
which exports pose data in DeepLabCut format, using the more general 4 levels (including "individuals"). So both single- and multi- animal data is saved in the multi-animal format.Some downstream tools (e.g. for action segmentation), may only accept single-animal DeepLabCut files. Therefore it would be useful to add a
split=True
argument tosave_poses.to_dlc_file()
, which will split multi-animal pose data into single-animal files.The text was updated successfully, but these errors were encountered: