deeplabcut.pose_estimation_pytorch.runners.logger
Classes:
| Name | Description |
|---|---|
BaseLogger |
Base class for logging training runs. |
CSVLogger |
Logger saving stats and metrics to a CSV file. |
ImageLoggerMixin |
Mixin for loggers that can log images. |
WandbLogger |
Wandb logger to track experiments and log data. |
Functions:
| Name | Description |
|---|---|
destroy_file_logging |
Resets the logging module to log everything to the console. |
setup_file_logging |
Sets up logging to a file. |
BaseLogger
Bases: ABC
Base class for logging training runs.
Methods:
| Name | Description |
|---|---|
log |
Logs data from a training run. |
log_config |
Logs the configuration data for a training run. |
save |
Saves the current training logs. |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log
abstractmethod
log_config
abstractmethod
Logs the configuration data for a training run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
the training configuration used for the run |
None
|
CSVLogger
Bases: BaseLogger
Logger saving stats and metrics to a CSV file.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the CSVLogger class. |
log |
Logs metrics from runs. |
log_config |
Does not do anything as the config should already be saved. |
save |
Saves the metrics to the file system. |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
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 | |
__init__
Initialize the CSVLogger class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The path of the folder containing training files. |
required |
|
str
|
The name of the file in which to store training stats |
required |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log
Logs metrics from runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
the metrics to log |
required |
|
int | None
|
The global step in processing. Defaults to None. |
None
|
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log_config
Does not do anything as the config should already be saved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Experiment config file. |
None
|
save
Saves the metrics to the file system.
ImageLoggerMixin
Bases: ABC
Mixin for loggers that can log images.
Before starting training, you should call select_images_to_log, which will
select a train and a test image for which inputs/outputs will always be logged.
Then logger.log_images should be called at every step - the logger will check if
anything needs to be uploaded, and take care of it.
Example
project_name = "example" run_name = "run-1" logger = WandbLogger(project_name, run_name) logger.select_images_to_log(train_loader, test_loader)
for i in range(epochs): for batch_inputs in train_loader: batch_labels = batch_data["annotations"] batch_inputs = batch_data["image"] batch_outputs = model(batch_inputs) batch_targets = model.get_target(batch_outputs, batch_labels) loss = criterion(batch_targets, batch_outputs) loss.backwards() optim.step()
logger.log_images(batch_inputs, batch_outputs, batch_targets)
for batch_inputs in train_loader:
...
logger.log_images(batch_inputs, batch_outputs, batch_targets)
Methods:
| Name | Description |
|---|---|
__init__ |
|
log_images |
Log images for a batch. |
select_images_to_log |
Selects the train and test images to log. |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
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 | |
__init__
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log_images
abstractmethod
log_images(
inputs: dict[str, Any], outputs: dict[str, Tensor], targets: dict[str, dict[str, Tensor]], step: int
) -> None
Log images for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
the inputs for the model, containing at least an "image" key |
required |
|
dict[str, Tensor]
|
the outputs of each model head |
required |
|
dict[str, dict[str, Tensor]]
|
the targets for each model head |
required |
|
int
|
the current step |
required |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
select_images_to_log
Selects the train and test images to log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DataLoader
|
the training dataloader |
required |
|
DataLoader
|
the inference dataloader |
required |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
WandbLogger
Bases: ImageLoggerMixin, BaseLogger
Wandb logger to track experiments and log data.
Refer to: https://docs.wandb.ai/guides for more information on wandb.
Attributes:
| Name | Type | Description |
|---|---|---|
run |
Run
|
The wandb run object associated with the current experiment. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the WandbLogger class. |
log |
Logs metrics from runs. |
log_config |
Updates the current run with the given config dict. |
log_images |
Log images for a batch. |
save |
Syncs all files to wandb with the policy specified. |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
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 | |
__init__
__init__(
project_name: str = "deeplabcut",
run_name: str = "tmp",
image_log_interval: int | None = None,
model: PoseModel = None,
train_folder: str = None,
**wandb_kwargs
) -> None
Initialize the WandbLogger class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the wandb project. Defaults to "deeplabcut". |
'deeplabcut'
|
|
str
|
The name of the wandb run. Defaults to "tmp". |
'tmp'
|
|
int | None
|
How often train/test images are logged in epochs (if None, train/test inputs are never logged). |
None
|
|
PoseModel
|
The model to log. Defaults to None. |
None
|
|
str
|
path to the train folder (used to store the W&B run identifiers) |
None
|
|
extra arguments to pass to |
{}
|
Example
logger = WandbLogger(project_name="mice", run_name="exp1", model=my_model)
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log
Logs metrics from runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
the metrics to log |
required |
|
int | None
|
The global step in processing. Defaults to None. |
None
|
Example
logger = WandbLogger() logger.log({"loss": 0.123}, step=100)
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log_config
Updates the current run with the given config dict.
Notes
self.run: A run is a unit of computation logged by wandb. self.run.config: Config object associated with this run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict
|
Experiment config file. |
None
|
Example
logger = WandbLogger() config = {"learning_rate": 0.001, "batch_size": 32} logger.log_config(config)
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
log_images
log_images(
inputs: dict[str, Any],
outputs: dict[str, dict[str, Tensor]],
targets: dict[str, dict[str, dict[str, Tensor]]],
step: int,
) -> None
Log images for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
the inputs for the model, containing at least an "image" key |
required |
|
dict[str, dict[str, Tensor]]
|
the outputs of each model head |
required |
|
dict[str, dict[str, dict[str, Tensor]]]
|
the targets for each model head |
required |
|
int
|
the current step |
required |
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
save
Syncs all files to wandb with the policy specified.
Notes
self.run: A run is a unit of computation logged by wandb. self.run.run.dir: The directory where files associated with the run are saved.
Example
logger = WandbLogger()
Training and logging
logger.save()
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
destroy_file_logging
Resets the logging module to log everything to the console.
Source code in deeplabcut/pose_estimation_pytorch/runners/logger.py
setup_file_logging
Sets up logging to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
the path where logs should be saved |
required |