deeplabcut.refine_training_dataset.outlier_frames
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. |
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. |
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
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
attempt_to_add_video
Add new videos to the config file at any stage of the project.
Parameters
config : string Full path of the config file in the project.
string
Full path of the video to add to the project.
bool, optional
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
False; if provided it must be either True or False.
list, optional
A list containing the list of cropping coordinates of the video. The default is set to None.
Returns
True iff the video was successfully added to the project
Source code in deeplabcut/refine_training_dataset/outlier_frames.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,
videos,
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
config: str Full path of the config.yaml file.
list[str]
The full paths to videos for analysis or a path to the directory, where all the videos with same extension are stored.
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.
str, optional, default="jump".
String specifying the algorithm used to detect the outliers.
'fitting'fits an Auto Regressive Integrated Moving Average model to the data and computes the distance to the estimated data. Larger distances than epsilon are then potentially identified as outliers'jump'identifies larger jumps than 'epsilon' in any body part'uncertain'looks for frames with confidence below p_bound'manual'launches a GUI from which the user can choose the frames'list'looks for user to provide a list of frame numbers to use, 'frames2use'. In this case,'extractionalgorithm'is forced to be'uniform.'
list[str], optional, default=None
If 'outlieralgorithm' is 'list', provide the list of frames here.
list[str] or str, optional, default="all"
This selects the body parts for which the comparisons with the outliers are
carried out. If "all", then all body parts from config.yaml are used. If a
list of strings that are a subset of the full list E.g. ['hand','Joystick'] for
the demo Reaching-Mackenzie-2018-08-30/config.yaml to select only these body
parts.
float between 0 and 1, optional, default=0.01
For outlieralgorithm 'uncertain' this parameter defines the likelihood
below which a body part will be flagged as a putative outlier.
float, optional, default=20
If 'outlieralgorithm' is 'fitting', this is the float bound according
to which frames are picked when the (average) body part estimate deviates from
model fit.
If 'outlieralgorithm' is 'jump', this is the float bound specifying the
distance by which body points jump from one frame to next (Euclidean distance).
int, optional, default=3
For outlieralgorithm 'fitting': Autoregressive degree of ARIMA model degree.
(Note we use SARIMAX without exogeneous and seasonal part)
See https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html
int, optional, default=1
For outlieralgorithm 'fitting': Moving Average degree of ARIMA model degree.
(Note we use SARIMAX without exogeneous and seasonal part)
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 ARIMA model. Only the distance is used however.
str, optional, default="kmeans"
String specifying the algorithm to use for selecting the frames from the
identified putatative outlier frames. Currently, deeplabcut supports either
kmeans or uniform based selection (same logic as for extract_frames).
bool, optional, default=False
If True, extract outliers without being asked for user feedback.
number, default=30
If "extractionalgorithm" is "kmeans", one can change the width to which
the images are downsampled (aspect ratio is fixed).
bool, optional, default=False
If False, each downsampled image is treated as a grayscale vector
(discarding color information). If True, then the color channels are
considered. This increases the computational complexity.
bool, optional, default=True
Uses openCV for loading & extractiong (otherwise moviepy (legacy)).
bool, optional, default=False
If True, frame are saved with predicted labels in each folder.
bool, optional, default=False
If True, newly-added videos (from which outlier frames are extracted) are copied to the project folder. By default, symbolic links are created instead.
str or None, optional, default=None
Specifies the destination folder that was used for storing analysis data. If
None, the path of the video is used.
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.
str, 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.
additional arguments.
For torch-based shuffles, can be used to specify: - snapshot_index - detector_snapshot_index
Returns
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
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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
find_outliers_in_raw_data
find_outliers_in_raw_data(
config,
pickle_file,
video_file,
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.
Parameter
config : str Absolute path to the project config.yaml.
str
Path to a _full.pickle or _assemblies.pickle.
str
Path to the corresponding video file for frame extraction.
float, optional (default=0.1)
Detection confidence threshold below which frames are flagged as containing outliers. Only considered if raw detections are passed in.
tuple, optional (default=(5, 95))
Assemblies are considered outliers if their areas are beyond the 5th and 95th percentiles. Must contain a lower and upper bound.
bool, optional (default=True)
If true, extract frames and the corresponding network predictions. Otherwise, only the frames are extracted.
string, optional (default="kmeans")
Outlier detection algorithm. Must be either uniform or kmeans.
bool, optional (default=False)
If True, newly-added videos (from which outlier frames are extracted) are copied to the project folder. By default, symbolic links are created instead.
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.
Parameter
pickled_data : dict
Data in the *_full.pickle file obtained after analyze_videos.
string, optional (default="uncertain")
Outlier detection algorithm. Currently, only 'uncertain' is supported for multi-animal raw detections.
float, optional (default=0.1)
Detection confidence threshold below which frames are flagged as
containing outliers. Only considered if algo==uncertain.
list, optional (default=None)
Indices in the list of labeled body parts to be kept of the analysis. By default, all keypoints are used for outlier search.
Returns
candidates : list Indices of video frames containing potential outliers
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
config: str Full path of the config.yaml file.
int or None, optional, default=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.
Examples
deeplabcut.merge_datasets('/analysis/project/reaching-task/config.yaml')