MNIST MLP vs CNN Architecture Comparison

By Anish Paleja · Published August 18, 2026

Head-to-head benchmark of multilayer perceptron and convolutional neural networks on MNIST with identical hyperparameters and data splits.

  • mnist
  • cnn
  • mlp
  • deep-learning
  • pytorch
  • comparison
7 cells3 experiments6 views1 forks

Inside this notebook

# MNIST: MLP vs CNN — head-to-head on branches Two architectures trained for **3 epochs** on the **same train/test split** (torchvision MNIST, 60k train / 10k test), each on its own branch: - **`mlp`** — 784 → 256 → 128 → 10, ReLU, dense baseline (~234k params) - **`cnn`** — Conv(1→32) → pool → Conv(32→64) → pool → FC(64·7·7→64) → 10 (~220k params, deliberately size-matched so the comparison is architectural, not about capacity) Both share the same seeded DataLoader (identical batch order), optimizer (Adam, lr 1e-3), loss, and batch size. The fork happens below; each branch runs `run_experiment("mlp")` / `run_experiment("cnn")` and persists results to disk, then we converge and compare side by side.

import json, os, time
import numpy as np
import torch
import torch.nn as nn
import torchvision
import torchvision.transforms as T
from torch.utils.data import DataLoader

# ---------- fixed seed & device ----------
SEED = 42
torch.manual_seed(SEED)
np.random.seed(SEED)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
print("device:", device)

# ---------- shared hyperparameters ----------
BATCH_SIZE = 64
EPOCHS = 3
…
device: cpu
artifacts: /home/user/mnist_mlp_cnn_artifacts
train: 60000  test: 10000
mlp params: 235,146
cnn params: 220,234
MNIST MLP vs CNN Architecture Comparison | Clusy