A neural network classifier built from scratch in NumPy (no PyTorch training loop) that recognizes 10 categories of clothing from 28×28 grayscale images using 5-fold cross-validation and a hand-coded Adam optimizer with learning rate decay.
NN for FASHION/
├── src/
│ ├── data/
│ │ └── fashion_numpy.py # Download, flatten & normalise Fashion MNIST
│ ├── models/
│ │ └── numpy_net.py # Layer_Dense, Dropout, ReLU, Softmax, Adam
│ └── training/
│ └── cross_val.py # k-fold CV, train_model, evaluate_model
├── checkpoints/ # Saved weights (git-ignored)
├── logs/ # Output logs (git-ignored)
├── train_numpy.py # Entry point
├── conftest.py
├── pytest.ini
└── requirements.txt
All layers are implemented manually in NumPy:
| Component | Detail |
|---|---|
Layer_Dense |
Linear transform with L1/L2 regularization on weights & biases |
Activation_ReLU |
Element-wise rectified linear unit |
Layer_Dropout |
Inverted dropout (disabled during inference) |
Activation_Softmax + Loss_CategoricalCrossentropy |
Fused for numerically stable backprop |
Optimizer_Adam |
Bias-corrected Adam with inverse learning rate decay |
Network: 784 → 512 → 512 → 256 → 128 → 10
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txtpython3 train_numpy.pyThis will:
- Download Fashion MNIST automatically
- Run 5-fold cross-validation on 60,000 training samples (20 epochs per fold)
- Retrain on the full training set (50 epochs)
- Report accuracy on the 10,000-sample test set
All hyperparameters are set inside train_numpy.py in the build_model() function:
| Parameter | Value |
|---|---|
| Hidden layers | 784 → 512 → 512 → 256 → 128 → 10 |
| L2 regularization | 5e-4 |
| Dropout rate | 0.05 |
| Learning rate | 0.0005 |
| LR decay | 1e-5 |
| Adam β₁ / β₂ | 0.9 / 0.999 |
| Batch size | 128 |
| CV folds | 5 |
| Metric | Value |
|---|---|
| Test Accuracy | ~89.5% |
| Optimizer | Adam with LR decay |
| Validation strategy | 5-fold cross-validation |
| Label | Class |
|---|---|
| 0 | T-shirt/top |
| 1 | Trouser |
| 2 | Pullover |
| 3 | Dress |
| 4 | Coat |
| 5 | Sandal |
| 6 | Shirt |
| 7 | Sneaker |
| 8 | Bag |
| 9 | Ankle boot |
| Concern | Tool |
|---|---|
| Numerics / forward & backward pass | NumPy |
| Dataset download | torchvision (utility only) |
| Python version | 3.11+ |
MIT