deeplabcut.pose_estimation_pytorch.apis.visualization
Methods to help with visualization of model outputs.
Functions:
| Name | Description |
|---|---|
create_labeled_images |
Plots model predictions on images. |
extract_maps |
Extracts the different maps output by DeepLabCut models, such as scoremaps, |
extract_model_outputs |
Obtains the outputs for a model for a list of images. |
extract_save_all_maps |
Extracts the scoremap, location refinement field and part affinity field |
create_labeled_images
create_labeled_images(
predictions: dict[str, dict[str, ndarray | ndarray]],
out_folder: str | Path,
pcutoff: float = 0.6,
bboxes_pcutoff: float = 0.6,
mode: str = "bodypart",
cmap: str | Colormap = "rainbow",
dot_size: int = 12,
alpha_value: float = 0.7,
skeleton: list[tuple[int, int]] | None = None,
skeleton_color: str = "k",
close_figure_after_save: bool = True,
)
Plots model predictions on images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, dict[str, ndarray | ndarray]]
|
The predictions to plot. A dictionary mapping image paths to the predictions made by the model on that image. The predictions should contain a "bodyparts" key, mapping to an array of shape (max_individuals, num_bodyparts, 3) containing predicted bodyparts. If there are any unique bodyparts predicted, then it should also contain a "unique_bodyparts" key, mapping to an array of shape (1, num_bodyparts, 3) containing the predicted unique bodyparts. |
required |
|
str | Path
|
The folder where model predictions should be saved. |
required |
|
float
|
The p-cutoff score above which predicted bodyparts are displayed with a "⋅" marker, and below which they are displayed with a "X" marker. |
0.6
|
|
float
|
The bounding box cutoff score, below which predicted bounding boxes are shown with a dashed line. |
0.6
|
|
str
|
One of "bodypart", "individual". Whether to color predictions by bodypart or individual. |
'bodypart'
|
|
str | Colormap
|
The colormap to use to plot predictions. |
'rainbow'
|
|
int
|
The size of the bodypart prediction markers. |
12
|
|
float
|
The transparency value of the bodypart prediction markers. |
0.7
|
|
list[tuple[int, int]] | None
|
If skeletons should be plotted, the list of bodyparts that constitute the skeletons. |
None
|
|
str
|
The color with which to plot the skeleton, if one is given. |
'k'
|
|
bool
|
Whether to close figures after saving the labeled images to disk. |
True
|
Source code in deeplabcut/pose_estimation_pytorch/apis/visualization.py
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 | |
extract_maps
extract_maps(
config,
shuffle: int = 0,
trainingsetindex: int | str = 0,
device: str | None = None,
rescale: bool = False,
indices: list[int] | None = None,
extract_paf: bool = True,
modelprefix: str | None = "",
snapshot_index: int | str | None = None,
detector_snapshot_index: int | str | None = None,
) -> dict
Extracts the different maps output by DeepLabCut models, such as scoremaps, location refinement fields and part-affinity fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Full path of the config.yaml file as a string. |
required | |
|
int
|
Index of the shuffle for which to extract maps |
0
|
|
Integer specifying which TrainingsetFraction to use. This variable can also be set to "all". |
required | |
|
bool
|
Evaluate the model at the 'global_scale' variable (as set in the
test/pose_config.yaml file for a particular project). Every image will be
resized according to that scale and prediction will be compared to the
resized ground truth. The error will be reported in pixels at rescaled to
the original size. Example:
For a [200, 200] pixel image evaluated at |
False
|
|
list[int] | None
|
Optionally, you can only obtain maps for a subset of images in your dataset. The indices given here are the indices of the images for which maps will be extracted. |
None
|
|
str | None
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. |
''
|
|
int | str | None
|
Index (starting at 0) of the snapshot we want to extract maps with. To evaluate the last one, use -1. To extract maps for all snapshots, use "all". |
None
|
|
int | str | None
|
Only for TD models. If defined, uses the detector with the given index for pose estimation. To extract maps for all detector snapshots, use "all". |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
a dict indexed by (trainingset_fraction, snapshot_index, image_index). For each key, the item contains a tuple of: (img, scmap, locref, paf, bpt_names, paf_graph, img_name, is_train) |
Examples
If you want to extract the data for image 0 and 103 (of the training set) for
model trained with shuffle 0.
>>> deeplabcut.extract_maps(config, 0, indices=[0, 103])
Source code in deeplabcut/pose_estimation_pytorch/apis/visualization.py
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 | |
extract_model_outputs
extract_model_outputs(
images: list[str] | list[Path],
model: PoseModel,
pre_processor: Preprocessor,
device: str = "auto",
context: list[dict[str, ndarray]] | None = None,
) -> list[dict[str, np.ndarray]]
Obtains the outputs for a model for a list of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] | list[Path]
|
List of image paths for which to get model outputs. |
required |
|
PoseModel
|
The model for which to get model outputs. |
required |
|
Preprocessor
|
The pre-processor used to prepare the images before giving them to the model. |
required |
|
str
|
The device on which to run inference. |
'auto'
|
|
list[dict[str, ndarray]] | None
|
The context for each image to give to the pre-processor. For top-down models, this context should contain the bounding boxes to use for each image. This should be in a format: [ {"bboxes": array of shape (num_bboxes, 4)}, # image 1 bboxes, {"bboxes": array of shape (num_bboxes, 4)}, # image 2 bboxes, ..., {"bboxes": array of shape (num_bboxes, 4)}, # image N bboxes, ] |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, ndarray]]
|
A list containing a dict for each input image, in the format: { inputs: a numpy array containing the inputs given to the model for the image context: the context given alongside the image outputs: a dict containing the model outputs } |
Source code in deeplabcut/pose_estimation_pytorch/apis/visualization.py
extract_save_all_maps
extract_save_all_maps(
config: str | Path,
shuffle: int = 1,
trainingsetindex: int = 0,
comparison_bodyparts: str | list[str] = "all",
extract_paf: bool = True,
all_paf_in_one: bool = True,
device: str | None = None,
rescale: bool = False,
indices: list[int] | None = None,
modelprefix: str | None = "",
snapshot_index: int | str | None = None,
detector_snapshot_index: int | str | None = None,
dest_folder: str | Path | None = None,
)
Extracts the scoremap, location refinement field and part affinity field prediction of the model. The maps will be rescaled to the size of the input image and stored in the corresponding model folder in /evaluation-results-pytorch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Full path of the config.yaml file as a string. |
required |
|
int
|
Index of the shuffle for which to extract maps |
1
|
|
Integer specifying which TrainingsetFraction to use. This variable can also be set to "all". |
required | |
|
str | list[str]
|
The average error will be computed for those body parts only (Has to be a subset of the body parts). |
'all'
|
|
bool
|
Extract part affinity fields by default. Note that turning it off will make the function much faster. |
True
|
|
bool
|
By default, all part affinity fields are displayed on a single frame. If false, individual fields are shown on separate frames. |
True
|
|
list[int] | None
|
Optionally, you can only obtain maps for a subset of images in your dataset. The indices given here are the indices of the images for which maps will be extracted. |
None
|
|
str | None
|
Directory containing the deeplabcut models to use when evaluating the network. By default, the models are assumed to exist in the project folder. |
''
|
|
int | str | None
|
Index (starting at 0) of the snapshot we want to extract maps with. To evaluate the last one, use -1. To extract maps for all snapshots, use "all". |
None
|
|
int | str | None
|
Only for TD models. If defined, uses the detector with the given index for pose estimation. To extract maps for all detector snapshots, use "all". |
None
|
Examples
Calculated maps for images 0, 1 and 33. >>> deeplabcut.extract_save_all_maps( >>> "/analysis/project/reaching-task/config.yaml", >>> shuffle=1, >>> indices=[0, 1, 33] >>> )
Source code in deeplabcut/pose_estimation_pytorch/apis/visualization.py
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 | |