peal.training.trainers

Supervised training loop for PEAL predictors and predictor distillation.

ModelTrainer trains a classifier (or a generator exposing track_generator_performance) from a PredictorConfig: it builds the model, dataloaders, optimizer, criterions and TensorBoard logger, runs epochs with optional mixup, label smoothing and PGD adversarial training, applies an early-stopping/regularisation scheme and writes model.cpl, checkpoints/*.cpl and config.yaml into model_path. The distill_* helpers relabel datasets with a teacher predictor’s outputs and train a student on them, which is how CFKD/DiDAE turn a repaired predictor into a stand-alone model. calculate_test_accuracy() is the shared (worst-)group accuracy evaluator.

Functions

calculate_test_accuracy

Compute the accuracy of model on a dataloader, optionally per group.

distill_1ofn_dataset

Relabel Image2ClassDataset (folder-per-class) data with a predictor.

distill_binary_dataset

Relabel Image2MixedDataset-style datasets with a predictor's outputs.

distill_dataloader_mixer

Recursively relabel every loader inside a DataloaderMixer.

distill_predictor

Train a student predictor on data relabelled by predictor.

get_predictor

Instantiate the predictor described by a PredictorConfig.

load_first_loadable

First checkpoint in paths that actually loads, or None if none does.

mixup

Mix each sample with a random partner (Zhang et al. mixup).

Classes

ModelTrainer

Train a predictor from a PredictorConfig with early stopping.