Skip to content
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
4 changes: 2 additions & 2 deletions src/custom_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def get_indices(image: torch.Tensor, kernel: torch.Tensor) -> tuple:
"""Get the indices to set up pixel vectors for convolution by matrix-multiplication.

Args:
image (jnp.ndarray): The input image of shape [height, width.]
kernel (jnp.ndarray): A 2d-convolution kernel.
image (torch.Tensor): The input image of shape [height, width].
kernel (torch.Tensor): A 2d-convolution kernel.

Returns:
tuple: An integer array with the indices, the number of rows in the result,
Expand Down
12 changes: 2 additions & 10 deletions src/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,7 @@ def zero_grad(model: Net) -> Net:

# TODO: Train the model.
# Use `loss.backward()`, `sgd_step` and `zero_grad`.
preds = model(imgs)
loss_val = cross_entropy(
label=th.nn.functional.one_hot(labels, num_classes=10), out=preds
)
loss_val.backward()

model = sgd_step(model, learning_rate=args.lr)
model = zero_grad(model)
epoch_loss.append(loss_val.item())

print(f"Loss: {sum(epoch_loss)/len(epoch_loss):2.4f}")

train_acc = get_acc(model=model, dataloader=train_loader)
Expand All @@ -176,7 +168,7 @@ def zero_grad(model: Net) -> Net:
test_acc = get_acc(model=model, dataloader=test_loader)
train_accs.append(per_epoch_train_acc)
val_accs.append(per_epoch_val_acc)
test_accs.append(train_acc)
test_accs.append(test_acc)
train_accs_np = np.stack(train_accs, axis=0)
val_accs_np = np.stack(val_accs, axis=0)
test_accs_np = np.stack(test_accs)
Expand Down
Loading