peal.training.trainers.distill_predictor¶
- peal.training.trainers.distill_predictor(predictor_distillation, base_path, predictor, predictor_datasource, replace_with_activation=None, tracking_level=4, predictor_distilled=None, only_last_layer=False, continue_training=False, task_config=None)[source]¶
Train a student predictor on data relabelled by
predictor.The relabelling strategy is chosen from the datasource: with
distill_from == "dataset"the original labels are kept; a(DataloaderMixer, WeightedDataloaderList)pair is relabelled withdistill_dataloader_mixer()/distill_binary_dataset();Image2MixedDatasetdata withdistill_binary_dataset(); andImage2ClassDatasetdata withdistill_1ofn_dataset(). The student is built frompredictor_distillation.architecture, or is a deep copy of the teacher, and is trained by aModelTrainerinto<base_path>/distilled_predictor.- Parameters:
predictor_distillation (
str,dictorPredictorConfig) – Student config;distill_fromandarchitectureare read here.base_path (
str) – Directory for relabelled data and the trained student.predictor (
torch.nn.Module) – Teacher whose predictions become the labels.predictor_datasource (
sequence) –(train, validation)datasets or loaders of the teacher.replace_with_activation (
{"leakysoftplus", "leakyrelu", None}, optional) – Swap the student’s ReLUs (leakysoftplus only for a freshly built student, leakyrelu only for a givenpredictor_distilled).tracking_level (
int, optional) – Verbosity written into the student config. Default 4.predictor_distilled (
torch.nn.Module, optional) – Student to train instead of building one.only_last_layer (
bool, optional) – Forwarded toModelTrainer.continue_training (
bool, optional) – Forwarded toModelTrainer.fit().task_config (
TaskConfig, optional) – Overrides the task config of the relabelled datasets.
- Returns:
The trained student.
- Return type:
- Raises:
Exception – When the datasource type matches no relabelling strategy.