mipcandy.training#
Module Contents#
Classes#
Functions#
API#
- class mipcandy.training.TrainerToolbox[source]#
Bases:
object- model: torch.nn.Module = None#
- optimizer: torch.optim.Optimizer = None#
- scheduler: torch.optim.lr_scheduler.LRScheduler = None#
- criterion: torch.nn.Module = None#
- ema: torch.nn.Module | None = None#
- class mipcandy.training.TrainerTracker[source]#
Bases:
object- epoch: int = 0#
- best_score: float = 'float(...)'#
- worst_case: int | None = None#
- class mipcandy.training.Trainer(trainer_folder: str | os.PathLike[str], dataloader: torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]], validation_dataloader: torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]], *, recoverable: bool = True, profiler: bool = False, device: torch.device | str = 'cpu', console: rich.console.Console = Console())[source]#
Bases:
mipcandy.layer.WithPaddingModule,mipcandy.layer.WithNetworkInitialization
- save_everything_for_recovery(toolbox: mipcandy.training.TrainerToolbox, tracker: mipcandy.training.TrainerTracker, **training_arguments) None[source]#
- load_tracker() mipcandy.training.TrainerTracker[source]#
- load_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool) mipcandy.training.TrainerToolbox[source]#
- etc(epoch: int, num_epochs: int, *, target_epoch: int | None = None, val_score_prediction_degree: int = 5) float[source]#
- set_frontend(frontend: type[mipcandy.frontend.Frontend], *, path_to_secrets: str | os.PathLike[str] | None = None) None[source]#
- save_metric_curve_combo(metrics: dict[str, Sequence[float]], *, title: str = 'All Metrics') None[source]#
- save_preview(image: torch.Tensor, label: torch.Tensor, output: torch.Tensor, *, quality: float = 0.75) None[source]#
- show_metrics(epoch: int, metrics: dict[str, list[float]], prefix: str, *, epochwise: bool = True, lookup_prefix: str = '', global_previous_index: int = -2) None[source]#
- Parameters:
epoch – the current epoch number
metrics – the metrics to show
prefix – the prefix to use for the table title
epochwise – whether the metrics are for one epoch (so that previous values are in self._metrics) or for all epochs (so that previous values are contained in :param: metrics itself)
lookup_prefix – the prefix to use for the lookup in self._metrics
global_previous_index – the index of the previous epoch in self._metrics
- abstractmethod build_scheduler(optimizer: torch.optim.Optimizer, num_epochs: int) torch.optim.lr_scheduler.LRScheduler[source]#
- _build_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool, *, model: torch.nn.Module | None = None) mipcandy.training.TrainerToolbox[source]#
- build_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool) mipcandy.training.TrainerToolbox[source]#
- sanity_check(template_model: torch.nn.Module, example_shape: mipcandy.types.AmbiguousShape) mipcandy.sanity_check.SanityCheckResult[source]#
- abstractmethod backward(images: torch.Tensor, labels: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float]][source]#
- train_batch(images: torch.Tensor, labels: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float]][source]#
- train_epoch(toolbox: mipcandy.training.TrainerToolbox) dict[str, list[float]][source]#
- train(num_epochs: int, *, note: str = '', num_checkpoints: int = 5, compile_model: bool = True, ema: bool = True, seed: int | None = None, early_stop_tolerance: int = 5, val_score_prediction: bool = True, val_score_prediction_degree: int = 5, save_preview: bool = True, preview_quality: float = 0.75) None[source]#
- abstractmethod validate_case(idx: int, image: torch.Tensor, label: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float], torch.Tensor][source]#
- validate(toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, list[float]]][source]#