Skip to content

Commit

Permalink
Adapted loops to new BaseTrainer closes [M0-Dev] Refactor logging a…
Browse files Browse the repository at this point in the history
…nd checkpoints as callbacks #23
  • Loading branch information
pab1s committed Apr 22, 2024
1 parent 85affd3 commit 863c2c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 1 addition & 3 deletions fine_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from torch.utils.data import DataLoader, random_split
from datasets.dataset import get_dataset
from datasets.transformations import get_transforms
from utils.metrics import Accuracy, Precision, Recall, F1Score
from utils.metrics import Accuracy, Precision
from models import get_model
from trainers import get_trainer
from os import path
Expand Down Expand Up @@ -62,7 +62,6 @@ def main(config_path):
train_loader=train_loader,
valid_loader=valid_loader,
num_epochs=config['training']['initial_epochs'],
log_path=log_filename,
plot_path=plot_filename
)

Expand All @@ -83,7 +82,6 @@ def main(config_path):
train_loader=train_loader,
valid_loader=valid_loader,
num_epochs=config['training']['fine_tuning_epochs'],
log_path=log_filename,
plot_path=plot_filename
)

Expand Down
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from torch.utils.data import DataLoader, random_split
from datasets.dataset import get_dataset
from callbacks import EarlyStopping, CSVLogging, EpochResultsLogging
from datasets.transformations import get_transforms
from utils.metrics import Accuracy, Precision, Recall, F1Score
from models import get_model
Expand Down Expand Up @@ -58,12 +59,22 @@ def main(config_path):
metrics=metrics
)

callbacks = [
CSVLogging(log_filename),
EpochResultsLogging(),
EarlyStopping(
monitor='val_loss',
patience=2,
delta=0.1,
verbose=True
)
]

trainer.train(
train_loader=train_loader,
valid_loader=valid_loader,
num_epochs=config['training']['num_epochs'],
log_path=log_filename,
plot_path=plot_filename
callbacks=callbacks,
)

trainer.evaluate(data_loader=test_loader)
Expand Down

0 comments on commit 863c2c6

Please sign in to comment.