Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
rev 13
  • Loading branch information
Borda committed Mar 14, 2023
commit f61f7add27ff6225f50d0592ccb4800d0446bfbd
3 changes: 1 addition & 2 deletions course_UvA-DL/13-contrastive-learning/.meta.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title: "Tutorial 13: Self-Supervised Contrastive Learning with SimCLR"
author: Phillip Lippe
created: 2021-08-30
updated: 2023-01-04
updated: 2021-08-30
license: CC BY-SA
tags:
- Image
Expand All @@ -20,7 +20,6 @@ requirements:
- torchvision
- matplotlib
- seaborn
- pytorch-lightning>=1.8
accelerator:
- CPU
- GPU
17 changes: 7 additions & 10 deletions course_UvA-DL/13-contrastive-learning/SimCLR.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
pl.seed_everything(42)

# Ensure that all operations are deterministic on GPU (if used) for reproducibility
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.determinstic = True
torch.backends.cudnn.benchmark = False

device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
Expand Down Expand Up @@ -357,14 +357,13 @@ def validation_step(self, batch, batch_idx):
def train_simclr(batch_size, max_epochs=500, **kwargs):
trainer = pl.Trainer(
default_root_dir=os.path.join(CHECKPOINT_PATH, "SimCLR"),
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
devices=1,
gpus=1 if str(device) == "cuda:0" else 0,
max_epochs=max_epochs,
callbacks=[
ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc_top5"),
LearningRateMonitor("epoch"),
],
enable_progress_bar=True,
progress_bar_refresh_rate=1,
)
trainer.logger._default_hp_metric = None # Optional logging argument that we don't need

Expand Down Expand Up @@ -541,14 +540,13 @@ def prepare_data_features(model, dataset):
def train_logreg(batch_size, train_feats_data, test_feats_data, model_suffix, max_epochs=100, **kwargs):
trainer = pl.Trainer(
default_root_dir=os.path.join(CHECKPOINT_PATH, "LogisticRegression"),
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
devices=1,
gpus=1 if str(device) == "cuda:0" else 0,
max_epochs=max_epochs,
callbacks=[
ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc"),
LearningRateMonitor("epoch"),
],
enable_progress_bar=False,
progress_bar_refresh_rate=0,
check_val_every_n_epoch=10,
)
trainer.logger._default_hp_metric = None
Expand Down Expand Up @@ -733,14 +731,13 @@ def test_step(self, batch, batch_idx):
def train_resnet(batch_size, max_epochs=100, **kwargs):
trainer = pl.Trainer(
default_root_dir=os.path.join(CHECKPOINT_PATH, "ResNet"),
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
devices=1,
gpus=1 if str(device) == "cuda:0" else 0,
max_epochs=max_epochs,
callbacks=[
ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc"),
LearningRateMonitor("epoch"),
],
enable_progress_bar=True,
progress_bar_refresh_rate=1,
check_val_every_n_epoch=2,
)
trainer.logger._default_hp_metric = None
Expand Down