Part 3: End‑to‑End CNN on MNIST (Keras • scikit‑learn • TensorFlow • PyTorch)

Author: Suyog Garg, Dated: 2025/11/18


Accompanying notebooks:

All notebooks save plots and metrics into ./artifacts/ for later comparison.

0) Why four mechanisms?

The comparison notebook summarizes test accuracy, train time, parameter count, and an approximate effective LOC (lines of code, measured by introspecting key functions).


1) Quick start (local or Colab)

Colab: upload any notebook, run all.
Local conda env (CPU baseline):

conda create -n mnist-cnn python=3.11 -c conda-forge -y
conda activate mnist-cnn
conda install numpy matplotlib scikit-learn scikeras tensorflow pytorch torchvision -c conda-forge -y

GPU users should install vendor wheels:


2) Running on a remote server (CPU / MPS / CUDA)

2.1 Headless Jupyter over SSH

# On remote
conda activate mnist-cnn
jupyter lab --no-browser --port 8890

# On your laptop
ssh -L 8890:localhost:8890 youruser@remote.host
# Then open http://localhost:8890

2.2 Device selection

2.3 CUDA vs CPU vs MPS


3) Outline of the session

  1. Start with A (Keras): quick win, show loss/accuracy plots.
  2. Continue B (scikit‑learn): fit/score API + tiny grid search.
  3. Then use C (TF Core): how to customize training with GradientTape etc.?
  4. Finally with D (PyTorch): point out explicit training loops and device placement.
  5. Run E (Compare) to produce the summary plots/table from the artifacts/*_metrics.json files.

4) Tips

Enjoy!