deeplabcut.post_processing
DeepLabCut2.0 Toolbox (deeplabcut.org) © A. & M. Mathis Labs https://github.com/DeepLabCut/DeepLabCut Please see AUTHORS for contributors.
https://github.com/DeepLabCut/DeepLabCut/blob/master/AUTHORS Licensed under GNU Lesser General Public License v3.0
Modules:
| Name | Description |
|---|---|
analyze_skeleton |
Contributed by Federico Claudi - https://github.com/FedeClaudi |
auxfun_multianimal |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxiliaryfunctions |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
filtering |
|
Functions:
| Name | Description |
|---|---|
collect_video_paths |
Collects video paths from a given set of data paths: directories, files, or a mix |
columnwise_spline_interp |
Perform cubic spline interpolation over the columns of data. All gaps of size |
filterpredictions |
Fits frame-by-frame pose predictions. |
renamed_parameter |
Support a renamed keyword argument while warning callers to update. |
collect_video_paths
collect_video_paths(
data_path: str | Path | list[str | Path],
extensions: str | Sequence[str] | None = None,
shuffle: bool = False,
exclude_patterns: Sequence[str] = DEFAULT_EXCLUDE_PATTERNS,
) -> list[Path]
Collects video paths from a given set of data paths: directories, files, or a mix of both. Directories are scanned one level deep (non-recursively).
Files and directories are treated differently with respect to extension filtering:
- File paths are accepted as-is when extensions is None; only filtered when
extensions is explicitly set.
- Directory contents are always filtered by extension: by SUPPORTED_VIDEOS when
extensions is None, or by the given value(s) otherwise.
- exclude_patterns are always applied to both files and directory contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | list[str | Path]
|
Path or list of paths to folders containing videos, or individual video files. Can be a mix of directories and files. |
required |
|
str | Sequence[str] | None
|
Controls extension filtering for collected video files.
- |
None
|
|
bool
|
Whether to shuffle the order of videos. If |
False
|
|
Sequence[str]
|
Patterns to exclude from the collection. Defaults to
|
DEFAULT_EXCLUDE_PATTERNS
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The paths of videos to analyze. Duplicate paths are removed. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If any path in |
ValueError
|
If |
Source code in deeplabcut/utils/auxfun_videos.py
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
columnwise_spline_interp
Perform cubic spline interpolation over the columns of data. All gaps of size lower than or equal to max_gap are filled, and data slightly smoothed.
Parameters
data : array_like 2D matrix of data. max_gap : int, optional Maximum gap size to fill. By default, all gaps are interpolated.
Returns
interpolated data with same shape as data
Source code in deeplabcut/post_processing/filtering.py
filterpredictions
filterpredictions(
config,
video,
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
filtertype="median",
windowlength=5,
p_bound=0.001,
ARdegree=3,
MAdegree=1,
alpha=0.01,
save_as_csv=True,
destfolder=None,
modelprefix="",
track_method="",
return_data=False,
**kwargs
)
Fits frame-by-frame pose predictions.
The pose predictions are fitted with ARIMA model (filtertype='arima') or median filter (default).
Parameters
config : string Full path of the config.yaml file.
string
Full path of the video to extract the frame from. Make sure that this video is already analyzed.
str | Sequence[str] | None, optional, default=None
Controls how videos are filtered, based on file extension.
File paths and directory contents are treated differently:
- None (default): file paths are accepted as-is; directories are
scanned for files with a recognized video extension.
- str or Sequence[str] (e.g. "mp4" or ["mp4", "avi"]):
both file paths and directory contents are filtered by the given
extension(s).
int, optional, default=1
The shuffle index of training dataset. The extracted frames will be stored in the labeled-dataset for the corresponding shuffle of training dataset.
int, optional, default=0
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml.
string, optional, default="median".
The filter type - 'arima', 'median' or 'spline'.
int, optional, default=5
For filtertype='median' filters the input array using a local window-size given by windowlength. The array will automatically be zero-padded. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.medfilt.html. The windowlenght should be an odd number. If filtertype='spline', windowlength is the maximal gap size to fill.
float between 0 and 1, optional, default=0.001
For filtertype 'arima' this parameter defines the likelihood below, below which a body part will be consided as missing data for filtering purposes.
int, optional, default=3
For filtertype 'arima' Autoregressive degree of Sarimax model degree. see https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html
int, optional, default=1
For filtertype 'arima' Moving Average degree of Sarimax model degree. See https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html
float, optional, default=0.01
Significance level for detecting outliers based on confidence interval of fitted SARIMAX model.
bool, optional, default=True
Saves the predictions in a .csv file.
string, optional, default=None
Specifies the destination folder for analysis data. If None, the path of
the video is used by default. Note that for subsequent analysis this folder
also needs to be passed.
str, optional, default=""
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder.
string, optional, default=""
Specifies the tracker used to generate the data. Empty by default (corresponding to a single animal project). For multiple animals, must be either 'box', 'skeleton', or 'ellipse' and will be taken from the config.yaml file if none is given.
bool, optional, default=False
If True, returns a dictionary of the filtered data keyed by video names.
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
video_to_filtered_df Dictionary mapping video filepaths to filtered dataframes.
* If no videos exist, the dictionary will be empty.
* If a video is not analyzed, the corresponding value in the dictionary will be
None.
Examples
Arima model:
deeplabcut.filterpredictions( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filterype='arima', ARdegree=5, MAdegree=2, )
Use median filter over 10 bins:
deeplabcut.filterpredictions( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, windowlength=10, )
One can then use the filtered rather than the frame-by-frame predictions by calling:
deeplabcut.plot_trajectories( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filtered=True, )
deeplabcut.create_labeled_video( 'C:\myproject\reaching-task\config.yaml', ['C:\myproject\trailtracking-task\test.mp4'], shuffle=3, filtered=True, )
Source code in deeplabcut/post_processing/filtering.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
renamed_parameter
renamed_parameter(*, old: str, new: str, since: str | None = None) -> Callable[[Callable[P, R]], Callable[P, R]]
Support a renamed keyword argument while warning callers to update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The old parameter name that callers may still pass. |
required |
|
str
|
The current parameter name the function actually accepts. |
required |
|
str | None
|
Version when the rename happened. |
None
|
Rules
newmust be the name used in the function signature and all internal call-sites.oldmust not appear in the signature.- Do not chain renames. If
Awas renamed toBandBis later renamed toC, replace theA→Bdecorator withA→Cdirectly rather than stacking a second decorator. Example: @renamed_parameter(old="A", new="C", since="12.4.0") @renamed_parameter(old="B", new="C", since="13.0.0") def func(*, C: int): print(f"C={C}") - Multiple independent renames on the same function (e.g.
batchsize→batch_sizeandvideotype→video_extensions) are fine as long as they do not form a chain. - This decorator only intercepts keyword arguments. Positional arguments are passed through unchanged; renaming a parameter that callers commonly pass positionally will not be caught.
Source code in deeplabcut/utils/deprecation.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |