Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add args and always save the model at the end of training #388

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions solo/methods/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ def __init__(self, cfg: omegaconf.DictConfig):
self.features_dim: int = self.backbone.inplanes
# remove fc layer
self.backbone.fc = nn.Identity()
cifar = cfg.data.dataset in ["cifar10", "cifar100"]
if cifar:
low_res = cfg.data.dataset in ["cifar10", "cifar100"] or cfg.method_kwargs.get("low_res", False)
if low_res:
self.backbone.conv1 = nn.Conv2d(
3, 64, kernel_size=3, stride=1, padding=2, bias=False
)
Expand Down Expand Up @@ -644,8 +644,8 @@ def __init__(
if self.backbone_name.startswith("resnet"):
# remove fc layer
self.momentum_backbone.fc = nn.Identity()
cifar = cfg.data.dataset in ["cifar10", "cifar100"]
if cifar:
low_res = cfg.data.dataset in ["cifar10", "cifar100"] or cfg.method_kwargs.get("low_res", False)
if low_res:
self.momentum_backbone.conv1 = nn.Conv2d(
3, 64, kernel_size=3, stride=1, padding=2, bias=False
)
Expand Down
11 changes: 10 additions & 1 deletion solo/utils/checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def on_train_start(self, trainer: pl.Trainer, _):
self.save_args(trainer)

def on_train_epoch_end(self, trainer: pl.Trainer, _):
"""Tries to save current checkpoint at the end of each train epoch.
"""Tries to save the current checkpoint at the end of each train epoch.

Args:
trainer (pl.Trainer): pytorch lightning trainer object.
Expand All @@ -173,3 +173,12 @@ def on_train_epoch_end(self, trainer: pl.Trainer, _):
epoch = trainer.current_epoch # type: ignore
if epoch % self.frequency == 0:
self.save(trainer)

def on_train_end(self, trainer: pl.Trainer, _):
"""Saves model at the end of training.

Args:
trainer (pl.Trainer): pytorch lightning trainer object.
"""

self.save(trainer)
Loading