SchedulerMixin

class fgvc.core.training.scheduler_mixin.SchedulerMixin(*args, scheduler: ReduceLROnPlateau | CosineLRScheduler | CosineAnnealingLR | None = None, validloader: DataLoader | None = None, **kwargs)

Mixin class that adds LR scheduler functionality to the trainer class.

The SchedulerMixin supports PyTorch and timm schedulers.

Parameters:
  • scheduler – LR scheduler algorithm.

  • validloader – Pytorch dataloader with validation data. SchedulerMixin uses it to validate it is not None when scheduler=ReduceLROnPlateau.

make_scheduler_step(epoch: int | None = None, *, valid_loss: float | None = None)

Make scheduler step after training one epoch.

The method uses different arguments depending on the scheduler type.

Parameters:
  • epoch – Current epoch number. The method expects start index 1 (instead of 0).

  • valid_loss – Average validation loss to use for ReduceLROnPlateau scheduler.

make_timm_scheduler_update(num_updates: int)

Make scheduler step update after training one iteration.

This is specific to timm schedulers.

Parameters:

num_updates – Iteration number.