deeplabcut.refine_training_dataset
Modules:
| Name | Description |
|---|---|
auxfun_multianimal |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
auxiliaryfunctions |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
conversioncode |
|
frameselectiontools |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
inferenceutils |
|
outlier_frames |
|
stitch |
|
tracklets |
|
visualization |
DeepLabCut2.0 Toolbox (deeplabcut.org) |
Classes:
| Name | Description |
|---|---|
TrackletManager |
|
VideoWriter |
|
Functions:
| Name | Description |
|---|---|
PlottingSingleFrame |
Label frame and save under imagename / this is already cropped (for clip) |
PlottingSingleFramecv2 |
Label frame and save under imagename / cap is not already cropped. |
attempt_to_add_video |
Add new videos to the config file at any stage of the project. |
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 |
compute_deviations |
Fits Seasonal AutoRegressive Integrated Moving Average with eXogenous regressors |
convertparms2start |
Creating a start value for sarimax in case of an value error |
extract_outlier_frames |
Extracts the outlier frames. |
find_outliers_in_raw_data |
Extract outlier frames from either raw detections or assemblies of multiple |
find_outliers_in_raw_detections |
Find outlier frames from the raw detections of multiple animals. |
merge_datasets |
Merge the original training dataset with the newly refined data. |
renamed_parameter |
Support a renamed keyword argument while warning callers to update. |
TrackletManager
Methods:
| Name | Description |
|---|---|
__init__ |
Manage tracklets for refinement and visualization. |
Source code in deeplabcut/refine_training_dataset/tracklets.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
__init__
Manage tracklets for refinement and visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to a configuration file. |
required |
|
int
|
Minimum swap length. Swaps shorter than 2 frames are discarded by default. Defaults to 2. |
2
|
|
int
|
Minimum tracklet length. Tracklets shorter than 2 frames are discarded by default. Defaults to 2. |
2
|
|
int
|
Number of frames to consider when filling in missing data. Defaults to 0. |
0
|
Examples:
manager = TrackletManager(config_path, min_swap_len=0, min_tracklet_len=0)
manager.load_tracklets_from_pickle(filename)
# Alternatively:
manager.load_tracklets_from_hdf(filename)
manager.find_swapping_bodypart_pairs()
Source code in deeplabcut/refine_training_dataset/tracklets.py
VideoWriter
Bases: VideoReader
Methods:
| Name | Description |
|---|---|
shorten |
Shorten the video from start to end. |
split |
Split a video into several shorter ones of equal duration. |
Source code in deeplabcut/utils/auxfun_videos.py
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
shorten
Shorten the video from start to end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall start. |
required |
|
str
|
Time formatted in hours:minutes:seconds, where shortened video shall end. |
required |
|
str
|
String added to the name of the shortened video. Defaults to 'short'. |
'short'
|
|
str
|
Folder the video is saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
Full path to the shortened video. |
Source code in deeplabcut/utils/auxfun_videos.py
split
Split a video into several shorter ones of equal duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
Number of shorter videos to produce. |
required |
|
str
|
String added to the name of the splits. Defaults to 'split'. |
'split'
|
|
str
|
Folder the video splits are saved into. By default, same as the original video. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
Paths of the video splits. |
Source code in deeplabcut/utils/auxfun_videos.py
PlottingSingleFrame
PlottingSingleFrame(
clip,
Dataframe,
bodyparts2plot,
tmpfolder,
index,
dotsize,
pcutoff,
alphavalue,
colors,
strwidth=4,
savelabeled=True,
)
Label frame and save under imagename / this is already cropped (for clip)
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
PlottingSingleFramecv2
PlottingSingleFramecv2(
cap, Dataframe, bodyparts2plot, tmpfolder, index, dotsize, pcutoff, alphavalue, colors, strwidth=4, savelabeled=True
)
Label frame and save under imagename / cap is not already cropped.
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
attempt_to_add_video
Add new videos to the config file at any stage of the project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
string
|
Full path of the config file in the project. |
required |
|
string
|
Full path of the video to add to the project. |
required |
|
bool
|
If this is set to True, the videos will be copied
to the project/videos directory. If False, the symlink of the videos will
be copied instead. The default is |
required |
|
list
|
A list containing the list of cropping coordinates of the video. Defaults to None. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True iff the video was successfully added to the project. |
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
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
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 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 | |
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:
| Name | Type | Description | Default |
|---|---|---|---|
|
array_like
|
2D matrix of data. |
required |
|
int
|
Maximum gap size to fill. By default, all gaps are interpolated. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
ndarray |
Interpolated data with the same shape as data. |
Source code in deeplabcut/post_processing/filtering.py
compute_deviations
Fits Seasonal AutoRegressive Integrated Moving Average with eXogenous regressors model to data and computes confidence interval as well as mean fit.
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
convertparms2start
Creating a start value for sarimax in case of an value error See: https://groups.google.com/forum/#!topic/pystatsmodels/S_Fo53F25Rk
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
extract_outlier_frames
extract_outlier_frames(
config: str | Path,
videos: list[str | Path],
video_extensions: str | Sequence[str] | None = None,
shuffle=1,
trainingsetindex=0,
outlieralgorithm="jump",
frames2use=None,
comparisonbodyparts="all",
epsilon=20,
p_bound=0.01,
ARdegree=3,
MAdegree=1,
alpha=0.01,
extractionalgorithm="kmeans",
automatic=False,
cluster_resizewidth=30,
cluster_color=False,
opencv=True,
savelabeled=False,
copy_videos=False,
destfolder=None,
modelprefix="",
track_method="",
**kwargs
)
Extracts the outlier frames.
Extracts the outlier frames if the predictions are not correct for a certain video from the cropped video running from start to stop as defined in config.yaml.
Another crucial parameter in config.yaml is how many frames to extract
numframes2extract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file. |
required |
|
list[str | Path]
|
The full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored. |
required |
|
str | Sequence[str] | None
|
Controls how |
None
|
|
int
|
The shuffle index of training dataset. The extracted frames will be stored in the labeled-dataset for the corresponding shuffle of training dataset. Defaults to 1. |
1
|
|
int
|
Integer specifying which TrainingsetFraction to use. Note that TrainingFraction is a list in config.yaml. Defaults to 0. |
0
|
|
str
|
String specifying the algorithm used to detect the outliers.
Defaults to "jump". |
'jump'
|
|
list[str]
|
If |
None
|
|
list[str] or str
|
This selects the body parts for
which the comparisons with the outliers are carried out. If |
'all'
|
|
float
|
For outlieralgorithm |
0.01
|
|
float
|
If |
20
|
|
int
|
For outlieralgorithm |
3
|
|
int
|
For outlieralgorithm |
1
|
|
float
|
Significance level for detecting outliers based on confidence interval of fitted ARIMA model. Only the distance is used however. Defaults to 0.01. |
0.01
|
|
str
|
String specifying the algorithm to use for
selecting the frames from the identified putatative outlier frames.
Currently, deeplabcut supports either |
'kmeans'
|
|
bool
|
If |
False
|
|
number
|
If |
30
|
|
bool
|
If |
False
|
|
bool
|
Uses openCV for loading & extractiong (otherwise moviepy (legacy)). Defaults to True. |
True
|
|
bool
|
If |
False
|
|
bool
|
If True, newly-added videos (from which outlier frames are extracted) are copied to the project folder. By default, symbolic links are created instead. Defaults to False. |
False
|
|
str or None
|
Specifies the destination folder that was
used for storing analysis data. If |
None
|
|
str
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. Defaults to "". |
''
|
|
str
|
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. Defaults to "". |
''
|
|
Additional arguments. For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index |
{}
|
Returns:
| Type | Description |
|---|---|
|
None |
Examples:
Extract the frames with default settings on Windows.
deeplabcut.extract_outlier_frames(
'C:\myproject\reaching-task\config.yaml',
['C:\yourusername\rig-95\Videos\reachingvideo1.avi'],
)
Extract the frames with default settings on Linux/MacOS.
deeplabcut.extract_outlier_frames(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/video/reachinvideo1.avi'],
)
Extract the frames using the "kmeans" algorithm.
deeplabcut.extract_outlier_frames(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/video/reachinvideo1.avi'],
extractionalgorithm='kmeans',
)
Extract the frames using the "kmeans" algorithm and "epsilon=5" pixels.
deeplabcut.extract_outlier_frames(
'/analysis/project/reaching-task/config.yaml',
['/analysis/project/video/reachinvideo1.avi'],
epsilon=5,
extractionalgorithm='kmeans',
)
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
find_outliers_in_raw_data
find_outliers_in_raw_data(
config: str | Path,
pickle_file: str | Path,
video_file: str | Path,
pcutoff=0.1,
percentiles=(5, 95),
with_annotations=True,
extraction_algo="kmeans",
copy_videos=False,
)
Extract outlier frames from either raw detections or assemblies of multiple animals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Absolute path to the project config.yaml. |
required |
|
str | Path
|
Path to a _full.pickle or _assemblies.pickle. |
required |
|
str | Path
|
Path to the corresponding video file for frame extraction. |
required |
|
float
|
Detection confidence threshold below which frames are flagged as containing outliers. Only considered if raw detections are passed in. Defaults to 0.1. |
0.1
|
|
tuple
|
Assemblies are considered outliers if their areas are beyond the 5th and 95th percentiles. Must contain a lower and upper bound. Defaults to (5, 95). |
(5, 95)
|
|
bool
|
If true, extract frames and the corresponding network predictions. Otherwise, only the frames are extracted. Defaults to True. |
True
|
|
string
|
Outlier detection algorithm. Must be either
|
'kmeans'
|
|
bool
|
If True, newly-added videos (from which outlier frames are extracted) are copied to the project folder. By default, symbolic links are created instead. Defaults to False. |
False
|
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
find_outliers_in_raw_detections
Find outlier frames from the raw detections of multiple animals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Data in the *_full.pickle file obtained after
|
required |
|
string
|
Outlier detection algorithm. Currently, only 'uncertain' is supported for multi-animal raw detections. Defaults to "uncertain". |
'uncertain'
|
|
float
|
Detection confidence threshold below which frames
are flagged as containing outliers. Only considered if |
0.1
|
|
list
|
Indices in the list of labeled body parts to be kept of the analysis. By default, all keypoints are used for outlier search. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Indices of video frames containing potential outliers, and the processed data dictionary. |
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
merge_datasets
Merge the original training dataset with the newly refined data.
Checks if the original training dataset can be merged with the newly refined training dataset. To do so it will check if the frames in all extracted video sets were relabeled.
If this is the case then the "iteration" variable is advanced by 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file. |
required |
|
int or None
|
If an integer is given the iteration variable is set to this value. This is only done if all datasets were labeled or refined. Defaults to None. |
None
|
Examples:
deeplabcut.merge_datasets("/analysis/project/reaching-task/config.yaml")
Source code in deeplabcut/refine_training_dataset/outlier_frames.py
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/core/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 | |