deeplabcut.pose_estimation_pytorch.apis.analyze_images
Functions:
| Name | Description |
|---|---|
analyze_image_folder |
Runs pose inference on a folder of images and returns the predictions. |
analyze_images |
Runs analysis on images using a pose model. |
parse_images_and_image_folders |
Parses image paths or directory paths into a single list of image paths. |
plot_images_coco |
Runs pose inference on a folder of images from a COCO dataset, and plots all |
superanimal_analyze_images |
This function inferences a superanimal model on a set of images and saves the |
analyze_image_folder
analyze_image_folder(
model_cfg: str | Path | dict,
images: str | Path | list[str] | list[Path],
snapshot_path: str | Path,
detector_path: str | Path | None = None,
frame_type: str | None = None,
device: str | None = None,
max_individuals: int | None = None,
progress_bar: bool = True,
filtered_detector_config: dict | None = None,
cond_provider: CondFromModel | None = None,
) -> dict[str, dict[str, np.ndarray | np.ndarray]]
Runs pose inference on a folder of images and returns the predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | dict
|
The model config (or its path) used to analyze the images. |
required |
|
str | Path | list[str] | list[Path]
|
The images to analyze. Can either be a directory containing images, or a list of paths of images. |
required |
|
str | Path
|
The path of the snapshot to use to analyze the images. |
required |
|
str | Path | None
|
The path of the detector snapshot to use to analyze the images, if a top-down model was used. |
None
|
|
str | None
|
Filters the images to analyze to only the ones with the given suffix
(e.g. setting |
None
|
|
str | None
|
The device to use to run image analysis. |
None
|
|
int | None
|
The maximum number of individuals to detect in each image. Set to the number of individuals in the project if None. |
None
|
|
bool
|
Whether to display a progress bar when running inference. |
True
|
|
dict | None
|
If using a filtered torchvision detector instead of a saved detector snapshot, specify the filtered detector configuration |
None
|
|
CondFromModel | None
|
If using a CTD model - this parameter is needed to provide the conditions |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, ndarray | ndarray]]
|
A dictionary mapping each image filename to the different types of predictions for it (e.g. "bodyparts", "unique_bodyparts", "bboxes", "bbox_scores") |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the pose model is a top-down model but no detector path is given |
Source code in deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
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 | |
analyze_images
analyze_images(
config: str | Path,
images: str | Path | list[str] | list[Path],
frame_type: str | None = None,
output_dir: str | Path | None = None,
shuffle: int = 1,
trainingsetindex: int = 0,
snapshot_index: int | None = None,
detector_snapshot_index: int | None = None,
modelprefix: str = "",
device: str | None = None,
max_individuals: int | None = None,
save_as_csv: bool = False,
progress_bar: bool = True,
plotting: bool | str = False,
pcutoff: float | None = None,
bbox_pcutoff: float | None = None,
plot_skeleton: bool = True,
ctd_conditions: dict | CondFromModel | None = None,
) -> dict[str, dict]
Runs analysis on images using a pose model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The project configuration file. |
required |
|
str | Path | list[str] | list[Path]
|
The image(s) to run inference on. Can be the path to an image, the path to a directory containing images, or a list of image paths or directories containing images. |
required |
|
str | None
|
Filters the images to analyze to only the ones with the given suffix
(e.g. setting |
None
|
|
str | Path | None
|
The directory where the predictions will be stored. |
None
|
|
int
|
The shuffle for which to run image analysis. |
1
|
|
int
|
The trainingsetindex for which to run image analysis. |
0
|
|
int | None
|
The index of the snapshot to use. Loaded from the project configuration file if None. |
None
|
|
int | None
|
For top-down models only. The index of the detector snapshot to use. Loaded from the project configuration file if None. |
None
|
|
str
|
The model prefix used for the shuffle. |
''
|
|
str | None
|
The device to use to run image analysis. |
None
|
|
int | None
|
The maximum number of individuals to detect in each image. Set to the number of individuals in the project if None. |
None
|
|
bool
|
Whether to also save the predictions as a CSV file. |
False
|
|
bool
|
Whether to display a progress bar when running inference. |
True
|
|
bool | str
|
Whether to plot predictions on images. |
False
|
|
float | None
|
The cutoff score when plotting pose predictions. Must be None or in (0, 1). If None, the pcutoff is read from the project configuration file. |
None
|
|
float | None
|
The cutoff score when plotting bounding box predictions. Must be None or in (0, 1). If None, it is read from the project configuration file. |
None
|
|
bool
|
If a skeleton is defined in the model configuration file, whether to plot the skeleton connecting the predicted bodyparts on the images. |
True
|
|
dict | CondFromModel | None
|
Only for CTD models. If None, the configuration for the condition provider will be loaded from the pytorch_config file (under the "inference": "conditions"). If the ctd_conditions is given as a dict, creates a CondFromModel from the dict. Otherwise, a CondFromModel can be given directly. Example configuration: |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
A dictionary mapping each image filename to the different types of predictions for it (e.g. "bodyparts", "unique_bodyparts", "bboxes", "bbox_scores") |
Source code in deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
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 | |
parse_images_and_image_folders
parse_images_and_image_folders(
images: str | Path | list[str] | list[Path], image_suffixes: tuple[str] = (".png", ".jpg", ".jpeg")
) -> list[str]
Parses image paths or directory paths into a single list of image paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | list[str] | list[Path]
|
Paths of images or folders containing images. |
required |
|
tuple[str]
|
Suffixes used for images. |
('.png', '.jpg', '.jpeg')
|
Returns:
| Type | Description |
|---|---|
list[str]
|
The images contained in the folders or directly the paths given as input |
Source code in deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
plot_images_coco
plot_images_coco(
model_cfg: str | Path | dict,
image_folder: str | Path,
snapshot_path: str | Path,
out_path: str = "test_images",
data_json_path: str = "",
detector_path: str | Path | None = None,
device: str | None = None,
max_individuals: int | None = None,
cond_provider: CondFromModel | None = None,
) -> list[dict]
Runs pose inference on a folder of images from a COCO dataset, and plots all predicted keypoints and bounding boxes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | dict
|
The model config (or its path) used to analyze the images. |
required |
|
str | Path
|
The path to the folder containing the images to analyze. |
required |
|
str | Path
|
The path of the snapshot to use to analyze the images. |
required |
|
str
|
The path of the folder where images should be output. |
'test_images'
|
|
str
|
The path to the JSON file containing ground truth data. |
''
|
|
str | Path | None
|
The path of the detector snapshot to use to analyze the images, if a top-down model was used. |
None
|
|
str | None
|
The device on which to run image inference |
None
|
|
int | None
|
The maximum number of individuals to detect in an image. |
None
|
|
CondFromModel | None
|
If using a CTD model - this parameter is needed to provide the conditions |
None
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
A list of dictionaries containing predictions made on each image. |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a top-down model configuration is given but detector_path is None |
Source code in deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
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 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
superanimal_analyze_images
superanimal_analyze_images(
superanimal_name: str,
model_name: str,
detector_name: str,
images: str | Path | list[str] | list[Path],
max_individuals: int,
out_folder: str | Path,
progress_bar: bool = True,
device: str | None = None,
pose_threshold: float = 0.4,
bbox_threshold: float = 0.6,
plot_skeleton: bool = True,
customized_model_config: str | Path | dict | None = None,
customized_pose_checkpoint: str | Path | None = None,
customized_detector_checkpoint: str | Path | None = None,
close_figure_after_save=True,
) -> dict[str, dict]
This function inferences a superanimal model on a set of images and saves the results as labeled images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
str The name of the SuperAnimal to analyze. Supported list: - "superanimal_bird" - "superanimal_topviewmouse" - "superanimal_quadruped" - "superanimal_superbird" - "superanimal_humanbody" |
required |
|
str
|
str The name of the pose model architecture to use for inference. To get a list of available models for a SuperAnimal, call: >>> import dlclibrary >>> superanimal_name = "superanimal_topviewmouse" >>> dlclibrary.get_available_models(superanimal_name) |
required |
|
str
|
str The name of the detector architecture to use for inference. To get a list of available detectors for a SuperAnimal, call: >>> import dlclibrary >>> superanimal_name = "superanimal_topviewmouse" >>> dlclibrary.get_available_detectors(superanimal_name) |
required |
|
str | Path | list[str] | list[Path]
|
str, Path, list[str], list[Path] The images to analyze. Can either be a directory containing images, or a list of paths of images. |
required |
|
int
|
int The maximum number of individuals to detect in each image. |
required |
|
str | Path
|
str | Path The directory where the labeled images will be saved. |
required |
|
bool
|
bool, default=True Whether to display a progress bar when running inference. |
True
|
|
str | None
|
str | None, default=None The device to use to run image analysis. |
None
|
|
float
|
float, default=0.4 The cutoff score when plotting pose predictions. To note, this is called pcutoff in other parts of the code. Must be in (0, 1). |
0.4
|
|
float
|
float, default=0.1 The minimum confidence score to keep bounding box detections. Must be in (0, 1). |
0.6
|
|
bool
|
bool, default=True If a skeleton is defined in the model configuration file, whether to plot the skeleton connecting the predicted bodyparts on the images. |
True
|
|
str | Path | dict | None
|
str | Path | dict | None A customized SuperAnimal model config, as an alternative to the default SuperAnimal model config. You can get the default SuperAnimal config with: >>> import deeplabcut.pose_estimation_pytorch.modelzoo as modelzoo >>> config = modelzoo.load_super_animal_config( >>> super_animal, model_name, detector_name, >>> ) |
None
|
|
str | Path | None
|
str | None A customized SuperAnimal pose checkpoint, as an alternative to the HuggingFace SuperAnimal models. |
None
|
|
str | Path | None
|
str | None A customized SuperAnimal detector checkpoint, as an alternative to the HuggingFace SuperAnimal models. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, dict]
|
The predictions made by the model for each image. |
Examples:
>>> from deeplabcut.pose_estimation_pytorch.apis import (
>>> superanimal_analyze_images
>>> )
>>> predictions = superanimal_analyze_images(
>>> superanimal_name="superanimal_topviewmouse",
>>> model_name="resnet_50",
>>> detector_name="fasterrcnn_mobilenet_v3_large_fpn",
>>> images="test_mouse_images",
>>> max_individuals=3,
>>> out_folder="test_mouse_images_labeled",
>>> device="cuda:0",
>>> pose_threshold=0.1,
>>> )
Source code in deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
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 | |