trainer_config
sleap_nn.config.trainer_config
¶
Serializable configuration classes for specifying all trainer config parameters.
These configuration classes are intended to specify all the parameters required to initialize the trainer config.
Classes:
Name | Description |
---|---|
DataLoaderConfig |
Train and val DataLoaderConfig. |
EarlyStoppingConfig |
Configuration for early_stopping. |
HardKeypointMiningConfig |
Configuration for online hard keypoint mining. |
LRSchedulerConfig |
Configuration for lr_scheduler. |
ModelCkptConfig |
Configuration for model checkpoint. |
OptimizerConfig |
Configuration for optimizer. |
ReduceLROnPlateauConfig |
Configuration for ReduceLROnPlateau scheduler. |
StepLRConfig |
Configuration for StepLR scheduler. |
TrainerConfig |
Configuration for trainer. |
WandBConfig |
Configuration for WandB. |
ZMQConfig |
Configuration of ZeroMQ-based monitoring of the training. |
Functions:
Name | Description |
---|---|
trainer_mapper |
Map the legacy trainer configuration to the new trainer configuration. |
DataLoaderConfig
¶
Train and val DataLoaderConfig.
Any parameters from Torch's DataLoader could be used.
Attributes:
Name | Type | Description |
---|---|---|
batch_size |
int
|
(int) Number of samples per batch or batch size for training/validation data. Default: |
shuffle |
bool
|
(bool) True to have the data reshuffled at every epoch. Default: |
num_workers |
int
|
(int) Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process. Default: |
Source code in sleap_nn/config/trainer_config.py
EarlyStoppingConfig
¶
Configuration for early_stopping.
Attributes:
Name | Type | Description |
---|---|---|
stop_training_on_plateau |
bool
|
(bool) True if early stopping should be enabled. Default: |
min_delta |
float
|
(float) Minimum change in the monitored quantity to qualify as an improvement, i.e. an absolute change of less than or equal to min_delta, will count as no improvement. Default: |
patience |
int
|
(int) Number of checks with no improvement after which training will be stopped. Under the default configuration, one check happens after every training epoch. Default: |
Source code in sleap_nn/config/trainer_config.py
HardKeypointMiningConfig
¶
Configuration for online hard keypoint mining.
Attributes:
Name | Type | Description |
---|---|---|
online_mining |
bool
|
If True, online hard keypoint mining (OHKM) will be enabled. When this is enabled, the loss is computed per keypoint (or edge for PAFs) and sorted from lowest (easy) to highest (hard). The hard keypoint loss will be scaled to have a higher weight in the total loss, encouraging the training to focus on tricky body parts that are more difficult to learn. If False, no mining will be performed and all keypoints will be weighted equally in the loss. Default: |
hard_to_easy_ratio |
float
|
The minimum ratio of the individual keypoint loss with respect to the lowest keypoint loss in order to be considered as "hard". This helps to switch focus on across groups of keypoints during training. Default: |
min_hard_keypoints |
int
|
The minimum number of keypoints that will be considered as "hard", even if they are not below the |
max_hard_keypoints |
Optional[int]
|
The maximum number of hard keypoints to apply scaling to. This can help when there are few very easy keypoints which may skew the ratio and result in loss scaling being applied to most keypoints, which can reduce the impact of hard mining altogether. Default: |
loss_scale |
float
|
Factor to scale the hard keypoint losses by. Default: |
Source code in sleap_nn/config/trainer_config.py
LRSchedulerConfig
¶
Configuration for lr_scheduler.
Attributes:
Name | Type | Description |
---|---|---|
step_lr |
Optional[StepLRConfig]
|
Configuration for StepLR scheduler. |
reduce_lr_on_plateau |
Optional[ReduceLROnPlateauConfig]
|
Configuration for ReduceLROnPlateau scheduler. |
Source code in sleap_nn/config/trainer_config.py
ModelCkptConfig
¶
Configuration for model checkpoint.
Any parameters from Lightning's ModelCheckpoint could be used.
Attributes:
Name | Type | Description |
---|---|---|
save_top_k |
int
|
(int) If save_top_k == k, the best k models according to the quantity monitored will be saved. If save_top_k == 0, no models are saved. If save_top_k == -1, all models are saved. Please note that the monitors are checked every every_n_epochs epochs. if save_top_k >= 2 and the callback is called multiple times inside an epoch, the name of the saved file will be appended with a version count starting with v1 unless enable_version_counter is set to False. Default: |
save_last |
Optional[bool]
|
(bool) When True, saves a last.ckpt whenever a checkpoint file gets saved. On a local filesystem, this will be a symbolic link, and otherwise a copy of the checkpoint file. This allows accessing the latest checkpoint in a deterministic manner. Default: |
Source code in sleap_nn/config/trainer_config.py
OptimizerConfig
¶
Configuration for optimizer.
Attributes:
Name | Type | Description |
---|---|---|
lr |
float
|
(float) Learning rate of type float. Default: |
amsgrad |
bool
|
(bool) Enable AMSGrad with the optimizer. Default: |
Source code in sleap_nn/config/trainer_config.py
ReduceLROnPlateauConfig
¶
Configuration for ReduceLROnPlateau scheduler.
Attributes:
Name | Type | Description |
---|---|---|
threshold |
float
|
(float) Threshold for measuring the new optimum, to only focus on significant changes. Default: |
threshold_mode |
str
|
(str) One of "rel", "abs". In rel mode, dynamic_threshold = best * ( 1 + threshold ) in max mode or best * ( 1 - threshold ) in min mode. In abs mode, dynamic_threshold = best + threshold in max mode or best - threshold in min mode. Default: |
cooldown |
int
|
(int) Number of epochs to wait before resuming normal operation after lr has been reduced. Default: |
patience |
int
|
(int) Number of epochs with no improvement after which learning rate will be reduced. For example, if patience = 2, then we will ignore the first 2 epochs with no improvement, and will only decrease the LR after the third epoch if the loss still hasn't improved then. Default: |
factor |
float
|
(float) Factor by which the learning rate will be reduced. new_lr = lr * factor. Default: |
min_lr |
Any
|
(float or List[float]) A scalar or a list of scalars. A lower bound on the learning rate of all param groups or each group respectively. Default: |
Methods:
Name | Description |
---|---|
validate_min_lr |
min_lr Validation. |
Source code in sleap_nn/config/trainer_config.py
validate_min_lr()
¶
min_lr Validation.
Ensures min_lr is a float>=0 or list of floats>=0
Source code in sleap_nn/config/trainer_config.py
StepLRConfig
¶
Configuration for StepLR scheduler.
Attributes:
Name | Type | Description |
---|---|---|
step_size |
int
|
(int) Period of learning rate decay. If step_size=10, then every 10 epochs, learning rate will be reduced by a factor of gamma. Default: |
gamma |
float
|
(float) Multiplicative factor of learning rate decay. Default: |
Source code in sleap_nn/config/trainer_config.py
TrainerConfig
¶
Configuration for trainer.
Attributes:
Name | Type | Description |
---|---|---|
train_data_loader |
DataLoaderConfig
|
(Note: Any parameters from Torch's DataLoader could be used.) |
val_data_loader |
DataLoaderConfig
|
(Similar to train_data_loader) |
model_ckpt |
ModelCkptConfig
|
(Note: Any parameters from Lightning's ModelCheckpoint could be used.) |
trainer_num_devices |
ModelCkptConfig
|
(int) Number of devices to use or "auto" to let Lightning decide. If |
trainer_device_indices |
Optional[List[int]]
|
(list) List of device indices to use. For example, |
trainer_accelerator |
str
|
(str) One of the ("cpu", "gpu", "mps", "auto"). "auto" recognises the machine the model is running on and chooses the appropriate accelerator for the Trainer to be connected to. Default: |
profiler |
Optional[str]
|
(str) Profiler for pytorch Trainer. One of ["advanced", "passthrough", "pytorch", "simple"]. Default: |
trainer_strategy |
str
|
(str) Training strategy, one of ["auto", "ddp", "fsdp", "ddp_find_unused_parameters_false", "ddp_find_unused_parameters_true", ...]. This supports any training strategy that is supported by |
enable_progress_bar |
bool
|
(bool) When True, enables printing the logs during training. Default: |
min_train_steps_per_epoch |
int
|
(int) Minimum number of iterations in a single epoch. (Useful if model is trained with very few data points). Refer limit_train_batches parameter of Torch Trainer. Default: |
train_steps_per_epoch |
Optional[int]
|
(int) Number of minibatches (steps) to train for in an epoch. If set to |
visualize_preds_during_training |
bool
|
(bool) If set to |
keep_viz |
bool
|
(bool) If set to |
max_epochs |
int
|
(int) Maximum number of epochs to run. Default: |
seed |
Optional[int]
|
(int) Seed value for the current experiment. If None, no seeding is applied. Default: |
use_wandb |
bool
|
(bool) True to enable wandb logging. Default: |
save_ckpt |
bool
|
(bool) True to enable checkpointing. Default: |
ckpt_dir |
Optional[str]
|
(str) Directory path where the |
run_name |
Optional[str]
|
(str) Name of the current run. The ckpts will be created in |
resume_ckpt_path |
Optional[str]
|
(str) Path to |
wandb |
WandBConfig
|
(Only if use_wandb is True, else skip this) |
optimizer_name |
str
|
(str) Optimizer to be used. One of ["Adam", "AdamW"]. Default: |
optimizer |
OptimizerConfig
|
create an optimizer configuration |
lr_scheduler |
Optional[LRSchedulerConfig]
|
create an lr_scheduler configuration |
early_stopping |
EarlyStoppingConfig
|
create an early_stopping configuration |
zmq |
Optional[ZMQConfig]
|
Zmq config with publish and controller port addresses. |
Methods:
Name | Description |
---|---|
validate_optimizer_name |
Validate that optimizer_name is one of the allowed values. |
validate_trainer_devices |
Validate the value of trainer_devices. |
Source code in sleap_nn/config/trainer_config.py
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 |
|
validate_optimizer_name(value)
staticmethod
¶
Validate that optimizer_name is one of the allowed values.
Source code in sleap_nn/config/trainer_config.py
validate_trainer_devices(value)
staticmethod
¶
Validate the value of trainer_devices.
Source code in sleap_nn/config/trainer_config.py
WandBConfig
¶
Configuration for WandB.
Only if use_wandb is True, else skip this
Attributes:
Name | Type | Description |
---|---|---|
entity |
Optional[str]
|
(str) Entity of wandb project. Default: |
project |
Optional[str]
|
(str) Project name for the wandb project. Default: |
name |
Optional[str]
|
(str) Name of the current run. Default: |
save_viz_imgs_wandb |
bool
|
(bool) If set to |
api_key |
Optional[str]
|
(str) API key. The API key is masked when saved to config files. Default: |
wandb_mode |
Optional[str]
|
(str) "offline" if only local logging is required. Default: |
prv_runid |
Optional[str]
|
(str) Previous run ID if training should be resumed from a previous ckpt. Default: |
group |
Optional[str]
|
(str) Group for wandb logging. Default: |
current_run_id |
Optional[str]
|
(str) Run ID for the current model training. (stored once the training starts). Default: |
Source code in sleap_nn/config/trainer_config.py
ZMQConfig
¶
Configuration of ZeroMQ-based monitoring of the training.
Attributes:
Name | Type | Description |
---|---|---|
controller_port |
Optional[int]
|
Port number of the endpoint to listen for command messages from. "tcp://tcp://127.0.0.1:{port_number}". Set to |
controller_polling_timeout |
int
|
Polling timeout in microseconds specified as an integer. This controls how long the poller should wait to receive a response and should be set to a small value to minimize the impact on training speed. Default: |
publish_port |
Optional[int]
|
Port number of the endpoint to publish updates to. "tcp://tcp://127.0.0.1:{port_number}". Set to |
Source code in sleap_nn/config/trainer_config.py
trainer_mapper(legacy_config)
¶
Map the legacy trainer configuration to the new trainer configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
legacy_config
|
dict
|
A dictionary containing the legacy trainer configuration. |
required |
Returns:
Type | Description |
---|---|
TrainerConfig
|
An instance of |
Source code in sleap_nn/config/trainer_config.py
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 |
|