uoft-cs/cifar10
Viewer β’ Updated β’ 60k β’ 355k β’ 142
A multi-layer perceptron trained in PyTorch with the architecture selected in Task 1.2.5.
train part of uoft-cs/cifar10 (50,000 images), true labels (noise level p = 0).torch.manual_seed(1127) before building the model, torch.Generator().manual_seed(1128) for the batch order.test part (10,000 images): accuracy 0.4770, loss 2.6550, mean F1 0.4772. Training accuracy 0.8840.uint8 image to 3072 numbers (img.reshape(3072), height, width, channel order).(x - mean) / std with mean and std from preprocessing.npz, computed on the 50,000 training images (population std; a zero std is replaced by 1).model.npz: arrays W0, b0, W1, b1, ... in layer order. W has shape (n_in, n_out), so a layer computes x @ W + b.preprocessing.npz: arrays mean and std, each of length 3072.import numpy as np
w, pre = np.load("model.npz"), np.load("preprocessing.npz")
x = (img.reshape(-1, 3072).astype(np.float64) / 255 - pre["mean"]) / pre["std"]
for i in range(2):
x = x @ w[f"W{i}"] + w[f"b{i}"]
if i < 2 - 1:
x = np.maximum(0, x) # ReLU
logits = x