diff options
Diffstat (limited to 'src/training')
82 files changed, 1936 insertions, 93 deletions
diff --git a/src/training/callbacks/__init__.py b/src/training/callbacks/__init__.py new file mode 100644 index 0000000..868d739 --- /dev/null +++ b/src/training/callbacks/__init__.py @@ -0,0 +1 @@ +"""TBC.""" diff --git a/src/training/callbacks/base.py b/src/training/callbacks/base.py new file mode 100644 index 0000000..d80a1e5 --- /dev/null +++ b/src/training/callbacks/base.py @@ -0,0 +1,101 @@ +"""Metaclass for callback functions.""" + +from abc import ABC +from typing import Callable, List, Type + + +class Callback(ABC): + """Metaclass for callbacks used in training.""" + + def on_fit_begin(self) -> None: + """Called when fit begins.""" + pass + + def on_fit_end(self) -> None: + """Called when fit ends.""" + pass + + def on_train_epoch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_train_epoch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_val_epoch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_val_epoch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_train_batch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_train_batch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_val_batch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_val_batch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + +class CallbackList: + """Container for abstracting away callback calls.""" + + def __init__(self, callbacks: List[Callable] = None) -> None: + """TBC.""" + self._callbacks = callbacks if callbacks is not None else [] + + def append(self, callback: Type[Callback]) -> None: + """Append new callback to callback list.""" + self.callbacks.append(callback) + + def on_fit_begin(self) -> None: + """Called when fit begins.""" + for _ in self._callbacks: + pass + + def on_fit_end(self) -> None: + """Called when fit ends.""" + pass + + def on_train_epoch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_train_epoch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_val_epoch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_val_epoch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_train_batch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_train_batch_end(self) -> None: + """Called at the end of an epoch.""" + pass + + def on_val_batch_begin(self) -> None: + """Called at the beginning of an epoch.""" + pass + + def on_val_batch_end(self) -> None: + """Called at the end of an epoch.""" + pass diff --git a/src/training/callbacks/early_stopping.py b/src/training/callbacks/early_stopping.py new file mode 100644 index 0000000..4da0e85 --- /dev/null +++ b/src/training/callbacks/early_stopping.py @@ -0,0 +1 @@ +"""Implements Early stopping for PyTorch model.""" diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/config.yml b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/config.yml new file mode 100644 index 0000000..2595325 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/config.yml @@ -0,0 +1,48 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: LeNet +network_args: + input_size: + - 28 + - 28 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/best.pt b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/best.pt Binary files differnew file mode 100644 index 0000000..6d78bad --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/last.pt b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/last.pt Binary files differnew file mode 100644 index 0000000..6d78bad --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0721_231455/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/config.yml b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/config.yml new file mode 100644 index 0000000..2595325 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/config.yml @@ -0,0 +1,48 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: LeNet +network_args: + input_size: + - 28 + - 28 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/best.pt b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/best.pt Binary files differnew file mode 100644 index 0000000..43a3891 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/last.pt b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/last.pt Binary files differnew file mode 100644 index 0000000..61c03f0 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_LeNet/0722_190746/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_124928/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_124928/config.yml new file mode 100644 index 0000000..2aa52cd --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_124928/config.yml @@ -0,0 +1,43 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: null +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.001 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141139/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141139/config.yml new file mode 100644 index 0000000..829297d --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141139/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.0003 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.0006 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/config.yml new file mode 100644 index 0000000..829297d --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.0003 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.0006 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/best.pt Binary files differnew file mode 100644 index 0000000..d0db78b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/last.pt Binary files differnew file mode 100644 index 0000000..d0db78b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141213/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/config.yml new file mode 100644 index 0000000..3df32bb --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.01 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.1 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/best.pt Binary files differnew file mode 100644 index 0000000..5914c8f --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/last.pt Binary files differnew file mode 100644 index 0000000..5ba44bb --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141433/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/best.pt Binary files differnew file mode 100644 index 0000000..96c21c1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/last.pt Binary files differnew file mode 100644 index 0000000..f024c0d --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_141702/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_145028/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_145028/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_145028/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_150212/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150212/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150212/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_150301/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150301/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150301/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_150317/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150317/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_150317/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/best.pt Binary files differnew file mode 100644 index 0000000..f833a89 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/last.pt Binary files differnew file mode 100644 index 0000000..f833a89 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151135/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_151408/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151408/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_151408/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_153144/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153144/config.yml new file mode 100644 index 0000000..829297d --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153144/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.0003 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.0006 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_153207/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153207/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153207/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/best.pt Binary files differnew file mode 100644 index 0000000..cbbc5e1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/last.pt Binary files differnew file mode 100644 index 0000000..cbbc5e1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_153310/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/config.yml new file mode 100644 index 0000000..fb75736 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/best.pt Binary files differnew file mode 100644 index 0000000..c93e3c6 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/last.pt Binary files differnew file mode 100644 index 0000000..c93e3c6 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_175150/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/config.yml new file mode 100644 index 0000000..1be5113 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: Adam +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 5.0e-05 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/best.pt Binary files differnew file mode 100644 index 0000000..580bad2 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/last.pt Binary files differnew file mode 100644 index 0000000..97e245c --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_180741/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/config.yml new file mode 100644 index 0000000..d2f98a2 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: Adamax +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/best.pt Binary files differnew file mode 100644 index 0000000..5a3df56 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/last.pt Binary files differnew file mode 100644 index 0000000..7f28dc3 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_181933/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/config.yml new file mode 100644 index 0000000..d2f98a2 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: Adamax +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/best.pt Binary files differnew file mode 100644 index 0000000..6f09780 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/last.pt Binary files differnew file mode 100644 index 0000000..3bb103e --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_183347/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/config.yml new file mode 100644 index 0000000..a7c66c5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/best.pt Binary files differnew file mode 100644 index 0000000..c3e3618 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/last.pt Binary files differnew file mode 100644 index 0000000..c3e3618 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190044/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/config.yml new file mode 100644 index 0000000..a7c66c5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/best.pt Binary files differnew file mode 100644 index 0000000..44d9b9b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/last.pt Binary files differnew file mode 100644 index 0000000..44d9b9b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190633/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/config.yml new file mode 100644 index 0000000..a7c66c5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/best.pt Binary files differnew file mode 100644 index 0000000..4a0333c --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/last.pt Binary files differnew file mode 100644 index 0000000..4a0333c --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_190738/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191111/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191111/config.yml new file mode 100644 index 0000000..a7c66c5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191111/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 0 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/config.yml new file mode 100644 index 0000000..08c344c --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/config.yml @@ -0,0 +1,46 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 1 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/best.pt Binary files differnew file mode 100644 index 0000000..076aae1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/last.pt Binary files differnew file mode 100644 index 0000000..076aae1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191310/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/config.yml new file mode 100644 index 0000000..0b9b10e --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/config.yml @@ -0,0 +1,42 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 1 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: null +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: RMSprop +optimizer_args: + alpha: 0.9 + centered: false + eps: 1.0e-07 + lr: 0.001 + momentum: 0 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/best.pt Binary files differnew file mode 100644 index 0000000..2fb0195 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/last.pt Binary files differnew file mode 100644 index 0000000..2fb0195 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191412/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/config.yml new file mode 100644 index 0000000..93c2854 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/config.yml @@ -0,0 +1,42 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 4 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: null +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: RMSprop +optimizer_args: + alpha: 0.9 + centered: false + eps: 1.0e-07 + lr: 0.001 + momentum: 0 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/best.pt Binary files differnew file mode 100644 index 0000000..9acc5b1 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/last.pt Binary files differnew file mode 100644 index 0000000..b8cc01c --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191504/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/config.yml new file mode 100644 index 0000000..7340941 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/config.yml @@ -0,0 +1,47 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/best.pt Binary files differnew file mode 100644 index 0000000..26bfb07 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/last.pt Binary files differnew file mode 100644 index 0000000..26bfb07 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0721_191826/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/config.yml new file mode 100644 index 0000000..90f0e13 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/config.yml @@ -0,0 +1,49 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 33 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +resume_experiment: last +train_args: + batch_size: 256 + epochs: 33 + val_metric: accuracy +verbosity: 1 diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/best.pt Binary files differnew file mode 100644 index 0000000..f0f297b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/last.pt Binary files differnew file mode 100644 index 0000000..c1adda5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_191559/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213125/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213125/config.yml new file mode 100644 index 0000000..8d77de5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213125/config.yml @@ -0,0 +1,49 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +resume_experiment: null +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy +verbosity: 2 diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/config.yml new file mode 100644 index 0000000..8d77de5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/config.yml @@ -0,0 +1,49 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +resume_experiment: null +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy +verbosity: 2 diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/best.pt Binary files differnew file mode 100644 index 0000000..e985997 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/last.pt Binary files differnew file mode 100644 index 0000000..e985997 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213413/model/last.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/config.yml b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/config.yml new file mode 100644 index 0000000..8d77de5 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/config.yml @@ -0,0 +1,49 @@ +criterion: CrossEntropyLoss +criterion_args: + ignore_index: -100 + reduction: mean + weight: null +data_loader_args: + batch_size: 256 + cuda: true + num_workers: 8 + sample_to_balance: true + seed: 4711 + shuffle: true + splits: + - train + - val + subsample_fraction: null + target_transform: null + transform: null +dataloader: EmnistDataLoader +device: cuda:0 +experiment_group: Sample Experiments +lr_scheduler: OneCycleLR +lr_scheduler_args: + epochs: 16 + max_lr: 0.001 + steps_per_epoch: 1314 +metrics: +- accuracy +model: CharacterModel +network: MLP +network_args: + input_size: 784 + num_layers: 3 + output_size: 62 +optimizer: AdamW +optimizer_args: + amsgrad: false + betas: + - 0.9 + - 0.999 + eps: 1.0e-08 + lr: 0.01 + weight_decay: 0 +resume_experiment: null +train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy +verbosity: 2 diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/best.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/best.pt Binary files differnew file mode 100644 index 0000000..0dde787 --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/best.pt diff --git a/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/last.pt b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/last.pt Binary files differnew file mode 100644 index 0000000..e02738b --- /dev/null +++ b/src/training/experiments/CharacterModel_Emnist_MLP/0722_213549/model/last.pt diff --git a/src/training/experiments/sample.yml b/src/training/experiments/sample.yml new file mode 100644 index 0000000..0ed560d --- /dev/null +++ b/src/training/experiments/sample.yml @@ -0,0 +1,43 @@ +experiment_group: Sample Experiments +experiments: + - dataloader: EmnistDataLoader + model: CharacterModel + metrics: [accuracy] + network: MLP + network_args: + input_shape: 784 + num_layers: 2 + train_args: + batch_size: 256 + epochs: 16 + criterion: CrossEntropyLoss + criterion_args: + weight: null + ignore_index: -100 + reduction: mean + optimizer: AdamW + optimizer_args: + lr: 3.e-4 + betas: [0.9, 0.999] + eps: 1.e-08 + weight_decay: 0 + amsgrad: false + lr_scheduler: OneCycleLR + lr_scheduler_args: + max_lr: 3.e-5 + epochs: 16 + # - dataloader: EmnistDataLoader + # model: CharacterModel + # network: MLP + # network_args: + # input_shape: 784 + # num_layers: 4 + # train_args: + # batch_size: 256 + # - dataloader: EmnistDataLoader + # model: CharacterModel + # network: LeNet + # network_args: + # input_shape: [28, 28] + # train_args: + # batch_size: 256 diff --git a/src/training/experiments/sample_experiment.yml b/src/training/experiments/sample_experiment.yml new file mode 100644 index 0000000..e8d5023 --- /dev/null +++ b/src/training/experiments/sample_experiment.yml @@ -0,0 +1,56 @@ +experiment_group: Sample Experiments +experiments: + - dataloader: EmnistDataLoader + data_loader_args: + splits: [train, val] + sample_to_balance: true + subsample_fraction: null + transform: null + target_transform: null + batch_size: 256 + shuffle: true + num_workers: 8 + cuda: true + seed: 4711 + model: CharacterModel + metrics: [accuracy] + network: MLP + network_args: + input_size: 784 + output_size: 62 + num_layers: 3 + # network: LeNet + # network_args: + # input_size: [28, 28] + # output_size: 62 + train_args: + batch_size: 256 + epochs: 16 + val_metric: accuracy + criterion: CrossEntropyLoss + criterion_args: + weight: null + ignore_index: -100 + reduction: mean + # optimizer: RMSprop + # optimizer_args: + # lr: 1.e-3 + # alpha: 0.9 + # eps: 1.e-7 + # momentum: 0 + # weight_decay: 0 + # centered: false + optimizer: AdamW + optimizer_args: + lr: 1.e-2 + betas: [0.9, 0.999] + eps: 1.e-08 + weight_decay: 0 + amsgrad: false + # lr_scheduler: null + lr_scheduler: OneCycleLR + lr_scheduler_args: + max_lr: 1.e-3 + epochs: 16 + verbosity: 2 # 0, 1, 2 + resume_experiment: null diff --git a/src/training/prepare_experiments.py b/src/training/prepare_experiments.py index 1ab8f00..eb872d7 100644 --- a/src/training/prepare_experiments.py +++ b/src/training/prepare_experiments.py @@ -1,22 +1,24 @@ """Run a experiment from a config file.""" import json +from subprocess import check_call import click from loguru import logger import yaml -def run_experiment(experiment_filename: str) -> None: +def run_experiments(experiments_filename: str) -> None: """Run experiment from file.""" - with open(experiment_filename) as f: + with open(experiments_filename) as f: experiments_config = yaml.safe_load(f) num_experiments = len(experiments_config["experiments"]) for index in range(num_experiments): experiment_config = experiments_config["experiments"][index] experiment_config["experiment_group"] = experiments_config["experiment_group"] - print( - f"python training/run_experiment.py --gpu=-1 '{json.dumps(experiment_config)}'" - ) + # cmd = f"python training/run_experiment.py --gpu=-1 '{json.dumps(experiment_config)}'" + cmd = f"poetry run run-experiment --gpu=-1 --save --experiment_config '{json.dumps(experiment_config)}'" + print(cmd) + check_call(cmd, shell=True) @click.command() @@ -26,9 +28,9 @@ def run_experiment(experiment_filename: str) -> None: type=str, help="Filename of Yaml file of experiments to run.", ) -def main(experiment_filename: str) -> None: +def main(experiments_filename: str) -> None: """Parse command-line arguments and run experiments from provided file.""" - run_experiment(experiment_filename) + run_experiments(experiments_filename) if __name__ == "__main__": diff --git a/src/training/run_experiment.py b/src/training/run_experiment.py index 8296e59..0b29ce9 100644 --- a/src/training/run_experiment.py +++ b/src/training/run_experiment.py @@ -1,17 +1,64 @@ """Script to run experiments.""" +from datetime import datetime +from glob import glob import importlib +import json import os -from typing import Dict +from pathlib import Path +import re +from typing import Callable, Dict, Tuple import click +from loguru import logger import torch +from tqdm import tqdm +from training.gpu_manager import GPUManager from training.train import Trainer +import yaml -def run_experiment( - experiment_config: Dict, save_weights: bool, gpu_index: int, use_wandb: bool = False -) -> None: - """Short summary.""" +EXPERIMENTS_DIRNAME = Path(__file__).parents[0].resolve() / "experiments" + + +DEFAULT_TRAIN_ARGS = {"batch_size": 64, "epochs": 16} + + +def get_level(experiment_config: Dict) -> int: + """Sets the logger level.""" + if experiment_config["verbosity"] == 0: + return 40 + elif experiment_config["verbosity"] == 1: + return 20 + else: + return 10 + + +def create_experiment_dir(model: Callable, experiment_config: Dict) -> Path: + """Create new experiment.""" + EXPERIMENTS_DIRNAME.mkdir(parents=True, exist_ok=True) + experiment_dir = EXPERIMENTS_DIRNAME / model.__name__ + if experiment_config["resume_experiment"] is None: + experiment = datetime.now().strftime("%m%d_%H%M%S") + logger.debug(f"Creating a new experiment called {experiment}") + else: + available_experiments = glob(str(experiment_dir) + "/*") + available_experiments.sort() + if experiment_config["resume_experiment"] == "last": + experiment = available_experiments[-1] + logger.debug(f"Resuming the latest experiment {experiment}") + else: + experiment = experiment_config["resume_experiment"] + assert ( + str(experiment_dir / experiment) in available_experiments + ), "Experiment does not exist." + logger.debug(f"Resuming the experiment {experiment}") + + experiment_dir = experiment_dir / experiment + return experiment_dir + + +def load_modules_and_arguments(experiment_config: Dict) -> Tuple[Callable, Dict]: + """Loads all modules and arguments.""" # Import the data loader module and arguments. datasets_module = importlib.import_module("text_recognizer.datasets") data_loader_ = getattr(datasets_module, experiment_config["dataloader"]) @@ -21,8 +68,11 @@ def run_experiment( models_module = importlib.import_module("text_recognizer.models") model_class_ = getattr(models_module, experiment_config["model"]) - # Import metric. - metric_fn_ = getattr(models_module, experiment_config["metric"]) + # Import metrics. + metric_fns_ = { + metric: getattr(models_module, metric) + for metric in experiment_config["metrics"] + } # Import network module and arguments. network_module = importlib.import_module("text_recognizer.networks") @@ -38,38 +88,145 @@ def run_experiment( optimizer_args = experiment_config.get("optimizer_args", {}) # Learning rate scheduler - lr_scheduler_ = None - lr_scheduler_args = None if experiment_config["lr_scheduler"] is not None: lr_scheduler_ = getattr( torch.optim.lr_scheduler, experiment_config["lr_scheduler"] ) lr_scheduler_args = experiment_config.get("lr_scheduler_args", {}) + else: + lr_scheduler_ = None + lr_scheduler_args = None + + model_args = { + "data_loader": data_loader_, + "data_loader_args": data_loader_args, + "metrics": metric_fns_, + "network_fn": network_fn_, + "network_args": network_args, + "criterion": criterion_, + "criterion_args": criterion_args, + "optimizer": optimizer_, + "optimizer_args": optimizer_args, + "lr_scheduler": lr_scheduler_, + "lr_scheduler_args": lr_scheduler_args, + } + + return model_class_, model_args + + +def run_experiment( + experiment_config: Dict, save_weights: bool, device: str, use_wandb: bool = False +) -> None: + """Runs an experiment.""" + + # Load the modules and model arguments. + model_class_, model_args = load_modules_and_arguments(experiment_config) + + # Initializes the model with experiment config. + model = model_class_(**model_args, device=device) + + # Create new experiment. + experiment_dir = create_experiment_dir(model, experiment_config) + + # Create log and model directories. + log_dir = experiment_dir / "log" + model_dir = experiment_dir / "model" + + # Get checkpoint path. + checkpoint_path = model_dir / "last.pt" + if not checkpoint_path.exists(): + checkpoint_path = None - # Device - # TODO fix gpu manager - device = None - - model = model_class_( - network_fn=network_fn_, - network_args=network_args, - data_loader=data_loader_, - data_loader_args=data_loader_args, - metrics=metric_fn_, - criterion=criterion_, - criterion_args=criterion_args, - optimizer=optimizer_, - optimizer_args=optimizer_args, - lr_scheduler=lr_scheduler_, - lr_scheduler_args=lr_scheduler_args, - device=device, + # Make sure the log directory exists. + log_dir.mkdir(parents=True, exist_ok=True) + + # Have to remove default logger to get tqdm to work properly. + logger.remove() + + # Fetch verbosity level. + level = get_level(experiment_config) + + logger.add(lambda msg: tqdm.write(msg, end=""), colorize=True, level=level) + logger.add( + str(log_dir / "train.log"), + format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}", ) - # TODO: Fix checkpoint path and wandb + if "cuda" in device: + gpu_index = re.sub("[^0-9]+", "", device) + logger.info( + f"Running experiment with config {experiment_config} on GPU {gpu_index}" + ) + else: + logger.info(f"Running experiment with config {experiment_config} on CPU") + + logger.info(f"The class mapping is {model.mapping}") + + # Pŕints a summary of the network in terminal. + model.summary() + + experiment_config["train_args"] = { + **DEFAULT_TRAIN_ARGS, + **experiment_config.get("train_args", {}), + } + + experiment_config["experiment_group"] = experiment_config.get( + "experiment_group", None + ) + + experiment_config["device"] = device + + # Save the config used in the experiment folder. + config_path = experiment_dir / "config.yml" + with open(str(config_path), "w") as f: + yaml.dump(experiment_config, f) + + # TODO: wandb trainer = Trainer( model=model, - epochs=experiment_config["epochs"], - val_metric=experiment_config["metric"], + model_dir=model_dir, + epochs=experiment_config["train_args"]["epochs"], + val_metric=experiment_config["train_args"]["val_metric"], + checkpoint_path=checkpoint_path, ) trainer.fit() + + score = trainer.validate() + + logger.info(f"Validation set evaluation: {score}") + + if save_weights: + model.save_weights(model_dir) + + +@click.command() +@click.option( + "--experiment_config", + type=str, + help='Experiment JSON, e.g. \'{"dataloader": "EmnistDataLoader", "model": "CharacterModel", "network": "mlp"}\'', +) +@click.option("--gpu", type=int, default=0, help="Provide the index of the GPU to use.") +@click.option( + "--save", + is_flag=True, + help="If set, the final weights will be saved to a canonical, version-controlled location.", +) +@click.option( + "--nowandb", is_flag=False, help="If true, do not use wandb for this run." +) +def main(experiment_config: str, gpu: int, save: bool, nowandb: bool) -> None: + """Run experiment.""" + if gpu < 0: + gpu_manager = GPUManager(True) + gpu = gpu_manager.get_free_gpu() + + device = "cuda:" + str(gpu) + + experiment_config = json.loads(experiment_config) + os.environ["CUDA_VISIBLE_DEVICES"] = f"{gpu}" + run_experiment(experiment_config, save, device, nowandb) + + +if __name__ == "__main__": + main() diff --git a/src/training/train.py b/src/training/train.py index 4a452b6..8cd5110 100644 --- a/src/training/train.py +++ b/src/training/train.py @@ -1,8 +1,8 @@ """Training script for PyTorch models.""" -from datetime import datetime from pathlib import Path -from typing import Callable, Dict, Optional +import time +from typing import Dict, Optional, Type from loguru import logger import numpy as np @@ -11,6 +11,7 @@ from tqdm import tqdm, trange from training.util import RunningAverage import wandb +from text_recognizer.models import Model torch.backends.cudnn.benchmark = True np.random.seed(4711) @@ -18,17 +19,16 @@ torch.manual_seed(4711) torch.cuda.manual_seed(4711) -EXPERIMENTS_DIRNAME = Path(__file__).parents[0].resolve() / "experiments" - - class Trainer: """Trainer for training PyTorch models.""" # TODO implement wandb. + # TODO implement Bayesian parameter search. def __init__( self, - model: Callable, + model: Type[Model], + model_dir: Path, epochs: int, val_metric: str = "accuracy", checkpoint_path: Optional[Path] = None, @@ -37,7 +37,8 @@ class Trainer: """Initialization of the Trainer. Args: - model (Callable): A model object. + model (Type[Model]): A model object. + model_dir (Path): Path to the model directory. epochs (int): Number of epochs to train. val_metric (str): The validation metric to evaluate the model on. Defaults to "accuracy". checkpoint_path (Optional[Path]): The path to a previously trained model. Defaults to None. @@ -45,6 +46,7 @@ class Trainer: """ self.model = model + self.model_dir = model_dir self.epochs = epochs self.checkpoint_path = checkpoint_path self.start_epoch = 0 @@ -58,7 +60,10 @@ class Trainer: self.val_metric = val_metric self.best_val_metric = 0.0 - logger.add(self.model.name + "_{time}.log") + + # Parse the name of the experiment. + experiment_dir = str(self.model_dir.parents[1]).split("/") + self.experiment_name = experiment_dir[-2] + "/" + experiment_dir[-1] def train(self) -> None: """Training loop.""" @@ -68,13 +73,13 @@ class Trainer: # Running average for the loss. loss_avg = RunningAverage() - data_loader = self.model.data_loaders["train"] + data_loader = self.model.data_loaders("train") with tqdm( total=len(data_loader), leave=False, unit="step", - bar_format="{n_fmt}/{total_fmt} {bar} {remaining} {rate_inv_fmt}{postfix}", + bar_format="{n_fmt}/{total_fmt} |{bar:20}| {remaining} {rate_inv_fmt}{postfix}", ) as t: for data, targets in data_loader: @@ -85,7 +90,7 @@ class Trainer: # Forward pass. # Get the network prediction. - output = self.model.predict(data) + output = self.model.network(data) # Compute the loss. loss = self.model.criterion(output, targets) @@ -105,16 +110,20 @@ class Trainer: output = output.data.cpu() targets = targets.data.cpu() metrics = { - metric: round(self.model.metrics[metric](output, targets), 4) + metric: self.model.metrics[metric](output, targets) for metric in self.model.metrics } - metrics["loss"] = round(loss_avg(), 4) + metrics["loss"] = loss_avg() # Update Tqdm progress bar. t.set_postfix(**metrics) t.update() - def evaluate(self) -> Dict: + # If the model has a learning rate scheduler, compute a step. + if self.model.lr_scheduler is not None: + self.model.lr_scheduler.step() + + def validate(self) -> Dict: """Evaluation loop. Returns: @@ -125,7 +134,7 @@ class Trainer: self.model.eval() # Running average for the loss. - data_loader = self.model.data_loaders["val"] + data_loader = self.model.data_loaders("val") # Running average for the loss. loss_avg = RunningAverage() @@ -137,7 +146,7 @@ class Trainer: total=len(data_loader), leave=False, unit="step", - bar_format="{n_fmt}/{total_fmt} {bar} {remaining} {rate_inv_fmt}{postfix}", + bar_format="{n_fmt}/{total_fmt} |{bar:20}| {remaining} {rate_inv_fmt}{postfix}", ) as t: for data, targets in data_loader: data, targets = ( @@ -145,22 +154,23 @@ class Trainer: targets.to(self.model.device), ) - # Forward pass. - # Get the network prediction. - output = self.model.predict(data) + with torch.no_grad(): + # Forward pass. + # Get the network prediction. + output = self.model.network(data) - # Compute the loss. - loss = self.model.criterion(output, targets) + # Compute the loss. + loss = self.model.criterion(output, targets) # Compute metrics. loss_avg.update(loss.item()) output = output.data.cpu() targets = targets.data.cpu() metrics = { - metric: round(self.model.metrics[metric](output, targets), 4) + metric: self.model.metrics[metric](output, targets) for metric in self.model.metrics } - metrics["loss"] = round(loss.item(), 4) + metrics["loss"] = loss.item() summary.append(metrics) @@ -170,7 +180,7 @@ class Trainer: # Compute mean of all metrics. metrics_mean = { - metric: np.mean(x[metric] for x in summary) for metric in summary[0] + metric: np.mean([x[metric] for x in summary]) for metric in summary[0] } metrics_str = " - ".join(f"{k}: {v}" for k, v in metrics_mean.items()) logger.debug(metrics_str) @@ -179,55 +189,34 @@ class Trainer: def fit(self) -> None: """Runs the training and evaluation loop.""" - # Create new experiment. - EXPERIMENTS_DIRNAME.mkdir(parents=True, exist_ok=True) - experiment = datetime.now().strftime("%m%d_%H%M%S") - experiment_dir = EXPERIMENTS_DIRNAME / self.model.network.__name__ / experiment - - # Create log and model directories. - log_dir = experiment_dir / "log" - model_dir = experiment_dir / "model" - - # Make sure the log directory exists. - log_dir.mkdir(parents=True, exist_ok=True) - - logger.add( - str(log_dir / "train.log"), - format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}", - ) - - logger.debug( - f"Running an experiment called {self.model.network.__name__}/{experiment}." - ) - - # Pŕints a summary of the network in terminal. - self.model.summary() + logger.debug(f"Running an experiment called {self.experiment_name}.") + t_start = time.time() # Run the training loop. for epoch in trange( - total=self.epochs, + self.epochs, initial=self.start_epoch, - leave=True, - bar_format="{desc}: {n_fmt}/{total_fmt} {bar} {remaining}{postfix}", + leave=False, + bar_format="{desc}: {n_fmt}/{total_fmt} |{bar:10}| {remaining}{postfix}", desc="Epoch", ): # Perform one training pass over the training set. self.train() # Evaluate the model on the validation set. - val_metrics = self.evaluate() - - # If the model has a learning rate scheduler, compute a step. - if self.model.lr_scheduler is not None: - self.model.lr_scheduler.step() + val_metrics = self.validate() # The validation metric to evaluate the model on, e.g. accuracy. val_metric = val_metrics[self.val_metric] is_best = val_metric >= self.best_val_metric - + self.best_val_metric = val_metric if is_best else self.best_val_metric # Save checkpoint. - self.model.save_checkpoint(model_dir, is_best, epoch, self.val_metric) + self.model.save_checkpoint(self.model_dir, is_best, epoch, self.val_metric) if self.start_epoch > 0 and epoch + self.start_epoch == self.epochs: logger.debug(f"Trained the model for {self.epochs} number of epochs.") break + + t_end = time.time() + t_training = t_end - t_start + logger.info(f"Training took {t_training:.2f} s.") |