deeplabcut.modelzoo.video_inference
Functions:
| Name | Description |
|---|---|
get_checkpoint_epoch |
Load a PyTorch checkpoint and return the current epoch number. |
video_inference_superanimal |
This function performs inference on videos using a pretrained SuperAnimal model. |
get_checkpoint_epoch
Load a PyTorch checkpoint and return the current epoch number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to the checkpoint file |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
Current epoch number, or 0 if not found |
Source code in deeplabcut/modelzoo/video_inference.py
video_inference_superanimal
video_inference_superanimal(
videos: str | list,
superanimal_name: str,
model_name: str,
detector_name: str | None = None,
scale_list: list | None = None,
video_extensions: str | Sequence[str] | None = None,
dest_folder: str | None = None,
cropping: list[int] | None = None,
video_adapt: bool = False,
plot_trajectories: bool = False,
batch_size: int = 1,
detector_batch_size: int = 1,
pcutoff: float = 0.1,
adapt_iterations: int = 1000,
pseudo_threshold: float = 0.1,
bbox_threshold: float = 0.9,
detector_epochs: int = 4,
pose_epochs: int = 4,
max_individuals: int = 10,
video_adapt_batch_size: int = 8,
device: str | None = "auto",
customized_pose_checkpoint: str | None = None,
customized_detector_checkpoint: str | None = None,
customized_model_config: str | None = None,
plot_bboxes: bool = True,
create_labeled_video: bool = True,
fmpose_return_3d: bool = False,
)
This function performs inference on videos using a pretrained SuperAnimal model.
IMPORTANT: Note that since we have both TensorFlow and PyTorch Engines, we will route the engine based on the model you select:
* dlcrnet -> TensorFlow
* all others - > PyTorch
Parameters
videos (str or list): The path to the video or a list of paths to videos.
superanimal_name (str): The name of the SuperAnimal dataset for which to load a pre-trained model.
model_name (str): The model architecture to use for inference.
detector_name (str): For top-down models (only available with the PyTorch framework), the type of object detector to use for inference.
scale_list (list): A list of different resolutions for the spatial pyramid. Used only for bottom up models.
video_extensions (str | Sequence[str] | None, 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).
dest_folder (str): The path to the folder where the results should be saved.
list or None, optional, default=None
Only for SuperAnimal models running with the PyTorch engine.
List of cropping coordinates as [x1, x2, y1, y2].
Note that the same cropping parameters will then be used for all videos.
If different video crops are desired, run video_inference_superanimal on
individual videos with the corresponding cropping coordinates.
video_adapt (bool): Whether to perform video adaptation. The default is False. You only need to perform it on one video because the adaptation generalizes to all videos that are similar.
plot_trajectories (bool): Whether to plot the trajectories. The default is False.
batch_size (int): The batch size to use for video inference. Only for PyTorch models.
detector_batch_size (int): The batch size to use for the detector during video inference. Only for PyTorch.
pcutoff (float): The p-value cutoff for the confidence of the prediction. The default is 0.1.
adapt_iterations (int): Number of iterations for adaptation training. Empirically 1000 is sufficient.
bbox_threshold (float): The pseudo-label threshold for the confidence of the detector. The default is 0.9
detector_epochs (int): Used in the PyTorch engine. The number of epochs for training the detector. The default is 4.
pose_epochs (int): Used in the PyTorch engine. The number of epochs for training the pose estimator. The default is 4.
pseudo_threshold (float): The pseudo-label threshold for the confidence of the prediction. The default is 0.1.
max_individuals (int): The maximum number of individuals in the video. The default is 30. Used only for top down models.
video_adapt_batch_size (int): The batch size to use for video adaptation.
device (str): The device to use for inference. The default is None (CPU). Used only for PyTorch models.
customized_pose_checkpoint (str): Used in the PyTorch engine. If specified, it replaces the default pose checkpoint.
customized_detector_checkpoint (str): Used in the PyTorch engine. If specified, it replaces the default detector checkpoint.
customized_model_config (str): Used for loading customized model config. Only supported in Pytorch
plot_bboxes (bool): If using Top-Down approach, whether to plot the detector's bounding boxes. The default is True.
create_labeled_video (bool): Specifies if a labeled video needs to be created, True by default.
fmpose_return_3d (bool):
Only used when model_name starts with "fmpose3d".
If True, include in-memory 3D poses in the return payload
(per video: {"df_2d": ..., "df_3d": ...}).
If False (default), keep the legacy return payload with only
the 2D DataFrame per video.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
Warning
|
If the superanimal_name will be deprecated in the future. |
FileNotFoundError
|
|
(Model Explanation) SuperAnimal-Quadruped:
superanimal_quadruped models aim to work across a large range of quadruped
animals, from horses, dogs, sheep, rodents, to elephants. The camera perspective is
orthogonal to the animal ("side view"), and most of the data includes the animals
face (thus the front and side of the animal). You will note we have several variants
that differ in speed vs. performance, so please do test them out on your data to see
which is best suited for your application. Also note we have a "video adaptation"
feature, which lets you adapt your data to the model in a self-supervised way.
No labeling needed!
All model snapshots are automatically downloaded to modelzoo/checkpoints when used.
- PLEASE SEE THE FULL DATASHEET: https://zenodo.org/records/10619173
- MORE DETAILS ON THE MODELS (detector, pose estimators): https://huggingface.co/mwmathis/DeepLabCutModelZoo-SuperAnimal-Quadruped
- We provide several models:
hrnet_w32(Top-Down pose estimation model, PyTorch engine) Anhrnet_w32is a top-down model that is paired with a detector. That means it takes a cropped image from an object detector and predicts the keypoints. When selecting this variant, adetector_namemust be set with one of the provided object detectors.dlcrnet(TensorFlow engine) This is a bottom-up model that predicts all keypoints then groups them into individuals. This can be faster, but more error prone.
- We provide one object detector (only for the PyTorch engine):
fasterrcnn_resnet50_fpn_v2This is a FasterRCNN model with a ResNet backbone, see https://pytorch.org/vision/stable/models/faster_rcnn.html
(Model Explanation) SuperAnimal-TopViewMouse:
superanimal_topviewmouse aims to work across lab mice in different lab settings
from a top-view perspective; this is very polar in many behavioral assays in freely
moving mice.
All model snapshots are automatically downloaded to modelzoo/checkpoints when used.
- PLEASE SEE THE FULL DATASHEET HERE
- MORE DETAILS ON THE MODELS (detector, pose estimators)
- We provide several models:
hrnet_w32(Top-Down pose estimation model, PyTorch engine) Anhrnet_w32is a top-down model that is paired with a detector. That means it takes a cropped image from an object detector and predicts the keypoints. When selecting this variant, adetector_namemust be set with one of the provided object detectors.dlcrnet(TensorFlow engine) This is a bottom-up model that predicts all keypoints then groups them into individuals. This can be faster, but more error prone.
- We provide one object detector (only for the PyTorch engine):
fasterrcnn_resnet50_fpn_v2This is a FasterRCNN model with a ResNet backbone, see https://pytorch.org/vision/stable/models/faster_rcnn.html
(Model Explanation) SuperAnimal-Bird:
superanimal_superbird model aims to work on various bird species. It was developed
during the 2024 DLC AI Residency Program. More info can be
found here
(Model Explanation) SuperAnimal-HumanBody:
superanimal_humanbody models aim to work across human body pose estimation
from various camera perspectives and environments. The models are designed to
handle different human poses, activities, and lighting conditions commonly
found in human motion analysis, sports analysis, and behavioral studies.
All model snapshots are automatically downloaded to modelzoo/checkpoints when used.
- We provide:
rtmpose_x(Top-Down pose estimation model, PyTorch engine) Anrtmpose_xis a top-down model that is paired with a detector. That means it takes a cropped image from an object detector and predicts the keypoints. When selecting this variant, adetector_namemust be set with one of the provided object detectors. This model uses 17 body parts in the COCO body7 format.
- The following object detectors can be used:
fasterrcnn_mobilenet_v3_large_fpn(default) This is a FasterRCNN model with a MobileNet backbonefasterrcnn_resnet50_fpnfasterrcnn_resnet50_fpn_v2For more info, see https://pytorch.org/vision/stable/models/faster_rcnn.html
Examples (PyTorch Engine)
import deeplabcut.modelzoo.video_inference.video_inference_superanimal as video_inference_superanimal video_inference_superanimal( videos=["/mnt/md0/shaokai/DLCdev/3mice_video1_short.mp4"], superanimal_name="superanimal_topviewmouse", model_name="hrnet_w32", detector_name="fasterrcnn_resnet50_fpn_v2", video_adapt=True, max_individuals=3, pseudo_threshold=0.1, bbox_threshold=0.9, detector_epochs=4, pose_epochs=4, )
Tips: * max_individuals: make sure you correctly give the number of individuals. Our inference api will only give up to max_individuals number of predictions. * pseudo_threshold: the higher you set, the more aggressive you filter low confidence predictions during video adaptation. * bbox_threshold: the higher you set, the more aggressive you filter low confidence bounding boxes during video adaptation. Different from our paper, we now add video adaptation to the object detector as well. * detector_epochs and pose_epochs do not need to be to high as video adaptation does not require too much training. However, you can make them higher if you see a substaintial gain in the training logs.
Examples
from deeplabcut.modelzoo.video_inference import video_inference_superanimal videos = ["/path/to/my/video.mp4"] superanimal_name = "superanimal_topviewmouse" video_extensions = "mp4" scale_list = [200, 300, 400] video_inference_superanimal( videos, superanimal_name, model_name="hrnet_w32", detector_name="fasterrcnn_resnet50_fpn_v2", scale_list = scale_list, video_extensions = video_extensions, video_adapt = True, )
Tips: scale_list: it's recommended to leave this as empty list []. Empirically [200, 300, 400] works well. We needed to do this as bottom-up models in TensorFlow are sensitive to the scales of the image. If you find your predictions not good without scale_list or it's too hard to find the right scale_list, you can try to use the PyTorch engine.
Source code in deeplabcut/modelzoo/video_inference.py
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 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 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |