Post

CIFAR-10 Image Classification

K-Nearest Neighbors, Support Vector Machine, Softmax, and a two-layer neural network on the CIFAR-10 dataset using NumPy.

CIFAR-10 Image Classification

Summary


  • Dataset: CIFAR-10 (50,000 training images, 10,000 test images; 32×32×3 color images across 10 classes)
  • Languages & Libraries: Python 3.x, NumPy, Matplotlib

Implementations

k-Nearest Neighbors (kNN)

  • Three distance-matrix methods: two-loop, one-loop, and fully vectorized.
  • Fully vectorized version achieved a 435× speedup (0.22 s vs. 96.9 s) over the two-loop baseline.
  • Performed 5-fold cross-validation over k ∈ {1,3,5,8,10,12,15,20,50,100}; k = 10 yielded the best test accuracy (28.2%, up from ~27%).

Support Vector Machine (SVM)

  • Implemented both naïve and fully vectorized loss and gradient computations.
  • Verified gradients with numerical checks, then trained via SGD to reach 37.7% train and 38.0% validation accuracy.

Softmax Classifier

  • Built looped and vectorized versions of Softmax loss/gradient.
  • Tuned learning rate and regularization to achieve 34.3% validation and 33.6% test accuracy.

Two-Layer Neural Network

  • Modular implementation with affine, ReLU, and “sandwich” layers.
  • Hyperparameter grid search led to >52% validation and ~58% test accuracy on CIFAR-10 .
  • Visualized learned weight matrices and misclassified examples for model interpretation.

Visualization

  • Training curves, confusion matrices, and weight visualizations are generated via Matplotlib and NumPy scripts.
This post is licensed under CC BY 4.0 by the author.