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 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
name: Format code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@

# %%
a = x + 2
b = a ** 2
b = a**2
c = b + 3
y = c.mean()
print("Y", y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,8 @@ def train_curve(optimizer_func, curve_func=pathological_curve_loss, num_updates=
# %%
def bivar_gaussian(w1, w2, x_mean=0.0, y_mean=0.0, x_sig=1.0, y_sig=1.0):
norm = 1 / (2 * np.pi * x_sig * y_sig)
x_exp = (-1 * (w1 - x_mean) ** 2) / (2 * x_sig ** 2)
y_exp = (-1 * (w2 - y_mean) ** 2) / (2 * y_sig ** 2)
x_exp = (-1 * (w1 - x_mean) ** 2) / (2 * x_sig**2)
y_exp = (-1 * (w2 - y_mean) ** 2) / (2 * y_sig**2)
return norm * torch.exp(x_exp + y_exp)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def training_step(self, batch, batch_idx):
real_out, fake_out = self.cnn(inp_imgs).chunk(2, dim=0)

# Calculate losses
reg_loss = self.hparams.alpha * (real_out ** 2 + fake_out ** 2).mean()
reg_loss = self.hparams.alpha * (real_out**2 + fake_out**2).mean()
cdiv_loss = fake_out.mean() - real_out.mean()
loss = reg_loss + cdiv_loss

Expand Down
6 changes: 3 additions & 3 deletions course_UvA-DL/11-vision-transformer/Vision_Transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(
self.patch_size = patch_size

# Layers/Networks
self.input_layer = nn.Linear(num_channels * (patch_size ** 2), embed_dim)
self.input_layer = nn.Linear(num_channels * (patch_size**2), embed_dim)
self.transformer = nn.Sequential(
*(AttentionBlock(embed_dim, hidden_dim, num_heads, dropout=dropout) for _ in range(num_layers))
)
Expand Down Expand Up @@ -403,8 +403,8 @@ def train_model(**kwargs):
model = ViT.load_from_checkpoint(trainer.checkpoint_callback.best_model_path)

# Test best model on validation and test set
val_result = trainer.test(model, test_dataloaders=val_loader, verbose=False)
test_result = trainer.test(model, test_dataloaders=test_loader, verbose=False)
val_result = trainer.test(model, dataloaders=val_loader, verbose=False)
test_result = trainer.test(model, dataloaders=test_loader, verbose=False)
result = {"test": test_result[0]["test_acc"], "val": val_result[0]["test_acc"]}

return model, result
Expand Down