deeplabcut.pose_estimation_pytorch.data.ctd
Classes:
| Name | Description |
|---|---|
CondFromFile |
A class providing conditions for a CTD model from a file. |
CondFromModel |
A class providing conditions for a CTD model from a BU model. |
CondProvider |
A class providing conditions for a CTD model. |
CondFromFile
Bases: CondProvider
A class providing conditions for a CTD model from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | None
|
The path to the file containing the conditions for the CTD model. These conditions must be pose predictions made by a BU model on the data |
None
|
|
Only load the conditions for the given image keys. |
required | |
|
A |
{}
|
Methods:
| Name | Description |
|---|---|
load_conditions |
Loads conditions for a model from a file. |
load_conditions_h5 |
Loads conditions for a model from a pandas DataFrame stored in an HDF file. |
load_conditions_json |
Loads conditions for a model from a JSON file. |
load_conditions_pickle |
Loads conditions from a |
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
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 | |
load_conditions
load_conditions(
images: list[str] | None = None, path_prefix: str | None = None
) -> dict[str, np.ndarray] | list[np.ndarray]
Loads conditions for a model from a file.
When loading conditions for individual images, the images must be provided
(indicating which images to load conditions for). A dict is returned containing
the conditions for each requested image.
When loading conditions for a video, the images parameter must be set to None.
A list is returned containing the conditions for each frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] | None
|
A list of image paths to load conditions for. |
None
|
|
str | None
|
Optional prefix to prepend to image paths when looking up conditions. This is useful when the paths in the conditions file are relative but the provided image paths are absolute, or vice versa. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray] | list[ndarray]
|
If "images" is given: a dictionary mapping image paths to condition arrays. Each array has shape (num_conditions, num_bodyparts, 3). If "images" is None: a list containing the conditions for each frame. |
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
load_conditions_h5
staticmethod
load_conditions_h5(
filepath: str | Path, images: list[str] | None = None, path_prefix: str | Path | None = None
) -> dict[str, np.ndarray] | list[np.ndarray]
Loads conditions for a model from a pandas DataFrame stored in an HDF file.
When loading conditions for individual images, the images must be provided
(indicating which images to load conditions for). A dict is returned containing
the conditions for each requested image.
When loading conditions for a video, the images parameter must be set to None.
A list is returned containing the conditions for each frame.
The DataFrame must be in the same format as DeepLabCut Predictions. For predictions on images (e.g. on a training/test set), the DataFrame should be in the format:
```
scorer model-name ...
individuals idv0 ... idvM
bodyparts bpt0 ... bptN
coords x y likelihood ... x y likelihood
----------------------------------------------------------------------------
(labeled-data, v0, 0.png) 87.0 62.0 0.73 ... 83.2 99.1 0.8326
```
While for conditions for videos, the DataFrame should be in the format:
```
scorer model-name ...
individuals idv0 ... idvM
bodyparts bpt0 ... bptN
coords x y likelihood ... x y likelihood
----------------------------------------------------------------------------
frame0000.png 87.0 62.0 0.73 ... 83.2 99.1 0.8326
```
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] | None
|
A list of image paths to load conditions for |
None
|
|
str | Path
|
Path to the JSON file containing conditions. |
required |
|
str | Path | None
|
Optional prefix to prepend to image paths when looking up conditions. This is useful when the paths in the conditions file are relative but the provided image paths are absolute, or vice versa. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray] | list[ndarray]
|
If "images" is given: a dictionary mapping image paths to condition arrays. Each array has shape (num_conditions, num_bodyparts, 3). |
If "images" is None: a list containing the conditions for each frame.
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
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 | |
load_conditions_json
staticmethod
load_conditions_json(
filepath: str | Path, images: list[str] | None = None, path_prefix: str | Path | None = None
) -> dict[str, np.ndarray] | list[np.ndarray]
Loads conditions for a model from a JSON file.
When loading conditions for individual images, the images must be provided
(indicating which images to load conditions for). A dict is returned containing
the conditions for each requested image. The JSON data structure should be:
```
{
"img000.png": [ # conditions for image 0
[ # condition 0 pose
[x, y, score], # keypoint 0
[x, y, score], # keypoint 1
...
[x, y, score], # keypoint N
],
[ ... ], # condition 1
...
[ ... ] # condition M
],
"img001.png": [...] # conditions for image 1
}
```
When loading conditions for a video, the images parameter must be set to None.
A list is returned containing the conditions for each frame. The JSON data
structure should be:
```
[
[ # conditions for frame 0
[ # condition 0 pose
[x, y, score], # keypoint 0
[x, y, score], # keypoint 1
...
[x, y, score], # keypoint N
],
[ ... ], # condition 1
...
[ ... ] # condition M
],
[ ... ], # conditions for frame 1
...
[ ... ] # conditions for frame N
]
```
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[str] | None
|
A list of image paths to load conditions for. |
None
|
|
str | Path
|
Path to the JSON file containing conditions. |
required |
|
str | Path | None
|
Optional prefix to prepend to image paths when looking up conditions. This is useful when the paths in the conditions file are relative but the provided image paths are absolute, or vice versa. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, ndarray] | list[ndarray]
|
A dictionary mapping image paths to condition arrays. Each array has shape (num_conditions, num_bodyparts, 3). |
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
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 | |
load_conditions_pickle
staticmethod
Loads conditions from a *_assemblies.pickle file containing predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Path to the Pickle file containing conditions. |
required |
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
CondFromModel
Bases: CondProvider
A class providing conditions for a CTD model from a BU model.
Attributes:
| Name | Type | Description |
|---|---|---|
config_path |
(Path)
The path to the |
|
snapshot_path |
(Path) The path to the BU snapshot to use to generate conditions for the CTD model. |
|
scorer |
str The scorer name for the BU model. This can be used to look for files containing conditions instead of recomputing them. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path | None
|
(Path)
The path to the |
None
|
|
str | Path | None
|
(Path) The path to the BU snapshot to use to generate conditions for the CTD model. |
None
|
|
A |
{}
|
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
CondProvider
Bases: ABC
A class providing conditions for a CTD model.
Methods:
| Name | Description |
|---|---|
get_loader_and_snapshot |
Creates a DLCLoader for the BU shuffle and the path to conditions snapshot. |
Source code in deeplabcut/pose_estimation_pytorch/data/ctd.py
get_loader_and_snapshot
abstractmethod
classmethod
get_loader_and_snapshot(
config: str | Path,
shuffle: int,
trainset_index: int = 0,
modelprefix: str = "",
snapshot: str | None = None,
snapshot_index: int | None = None,
) -> tuple[DLCLoader, Snapshot]
Creates a DLCLoader for the BU shuffle and the path to conditions snapshot.
One of snapshot or snapshot_index must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Path to the DeepLabCut project config, or the project config itself |
required |
|
int
|
The index of the TrainingsetFraction for which to load data |
0
|
|
int
|
The index of the shuffle for which to load data. |
required |
|
str
|
The modelprefix for the shuffle. |
''
|
|
str | None
|
The name of the snapshot to use. |
None
|
|
int | None
|
The index of the snapshot to use. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
loader |
tuple[DLCLoader, Snapshot]
|
The DLCLoader for the BU shuffle. snapshot: The BU Snapshot to use for conditions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given shuffle is not for a BU model. |