physioex.train.trainer.Trainer#

class physioex.train.trainer.Trainer[source]#

Bases: object

__init__()#

Methods

__init__()

build_dataloaders(dataset[, ...])

evaluate(model, dataset[, metrics, ...])

load_checkpoint(model, path[, optimizer])

save_checkpoint(model, path[, epoch, optimizer])

train(model, dataset[, checkpoint_path, ...])

voting_evaluate(model, dataset[, L, ...])

Evaluate using sliding-window voting over full-night sequences.

classmethod voting_evaluate(model, dataset, L=21, metrics=None, batch_size=1, num_workers=None, pin_memory=False, prefetch_factor=2, persistent_workers=False, fold=0, gpu_id=None, ignore_index=-1, seed=42, per_subject=False, ci_method='bootstrap', n_bootstrap=1000)[source]#

Evaluate using sliding-window voting over full-night sequences.

For each subject, the night is scanned with L-length windows at L different starting offsets (0 to L-1). Predictions from overlapping windows are averaged. This matches the evaluation protocol of the current library’s voting_strategy().

Parameters:
  • model (Module) – model with forward(x) accepting shape (batch, L, …) and returning (batch, L, n_classes)

  • dataset (PhysioExDataset | DataLoader) – a PhysioExDataset (will be wrapped in eval loader) OR a DataLoader

  • L (int) – sequence length the model was trained on (default 21)

  • metrics (dict) – dict of metric_name -> callable(preds, targets, ignore_index=…). Defaults to accuracy/f1/precision/recall/cohen_kappa/confusion_matrix/support.

  • ignore_index (int) – label value for padded epochs (default -1)

  • batch_size (int)

  • num_workers (int)

  • pin_memory (bool)

  • prefetch_factor (int)

  • persistent_workers (bool)

  • fold (int)

  • gpu_id (int)

  • seed (int)

  • per_subject (bool)

  • ci_method (str)

  • n_bootstrap (int)

Returns:

dict of metric_name -> value

Return type:

dict