This project investigates supervised classification on the Chinese MNIST dataset using two baseline model families:
- Logistic Regression (single linear layer) – a capacity baseline.
- Multi-Layer Perceptron (MLP) with configurable depth, width patterns, dropout, and optimizer sweeps.
The goal is to quantify how architectural depth/width, batch size, optimizer choice (SGD+Momentum vs Adam), and learning rate impact convergence behavior and generalization on a mid‑sized grayscale digit dataset with 15 target classes.
Key design principles:
- Reproducible training loops with early stopping (monitoring validation accuracy).
- Systematic hyperparameter sweeps with per‑run metric persistence (JSON + aggregated CSV).
- Strict, explicit checkpoint naming to enable automated parsing during model selection.
- Lightweight, interpretable baselines before exploring convolutional or more modern architectures.
Chinese MNIST consists of grayscale images (handwritten Chinese numeral variants). The project pipeline:
| Step | Action |
|---|---|
| 1 | Download & extract data.zip (if missing) |
| 2 | Generate stratified splits: train / val / test (80 / 10 / 10) |
| 3 | Optional label variant control (value, value_character, or code) |
| 4 | Apply light train-time augmentation: small rotation + affine translation |
| 5 | Transform → Grayscale → Resize (64×64) → ToTensor → Normalize → Flatten |
(*Normalization and flattening are configurable. Flattening is enabled for linear / MLP baselines.)
Augmentation is intentionally conservative to avoid distorting digit structure. All transforms are defined in preprocessing_utils.py.
Single Linear(input_dim, num_classes) layer. Serves as a minimal baseline to detect whether the dataset is linearly separable in raw pixel space (after flattening).
Hidden layer blocks: Linear → BatchNorm1d → ReLU → Dropout repeated per hidden layer. Output layer is linear (raw logits). Depth and width patterns explored include:
mlp_1x512mlp_2x256mlp_3x512-256-128- (Easily extensible to 4+ layer tapered variants.)
Regularization: Dropout (0.5) + Weight Decay (5e-4). Adam and SGD+Momentum (0.9) compared across coarse→fine learning rates.
| Dimension | Values |
|---|---|
| Batch Size | 32, 256 |
| Optimizers | Adam, SGD (momentum=0.9) |
| Learning Rates | 0.01, 0.001, 0.0005 |
| Epoch Ceiling | 30 (logreg), 50 (MLP) |
| Early Stopping | Patience = 5 (val accuracy) |
| Architectures | See model list above |
Each (architecture, batch_size, optimizer, lr) combination produces a best‑validation checkpoint. File naming pattern examples:
checkpoints/log_reg/model_{batch}_{optimizer}_{lr}.pth
checkpoints/mlp/mlp_3x512-256-128_{batch}_{optimizer}_{lr}.pth
Hyperparameter metrics for every epoch are persisted:
- Per‑run JSON:
metrics/mlp/*.json - Aggregated CSV:
metrics/mlp/runs_detailed.csv
This enables offline analytics (ranking, plotting without re‑training) and reproducible result summaries.
During the test phase:
- Checkpoints are enumerated and parsed via regex to recover architecture + hyperparameters.
- Each model is reconstructed and evaluated on the test loader matching its batch size.
- Best model selected by test accuracy (ties can be extended to include macro‑F1).
- Confusion matrix + performance curves for the best run are rendered to
plots/. - A lightweight qualitative inference stage samples one test image per class for visual confirmation and class confidence inspection.
Metric focus: Accuracy (primary), Macro‑F1 (class balance), qualitative inspection (misclass patterns).
Install Python 3.10+ and required packages (PyTorch, torchvision, torchinfo, seaborn, scikit‑learn, pandas, numpy, matplotlib). If a requirements.txt is added later, prefer that.
python log_reg.pyOpen presentation.ipynb and execute sequentially, or adapt the training loops for CLI execution.
- Checkpoints:
checkpoints/\ - Metrics JSON/CSV:
metrics/\ - Plots (curves & confusion matrices):
plots/
Run the later notebook cells (section “Inference”) or re‑load a checkpoint and call the predict_image utility.
├── log_reg.py # Logistic regression experiment script
├── mlp_basic.py # MLP first approach (single config)
├── mlp.py # Configurable MLP model definition
├── models_utils.py # Training / evaluation / plotting utilities
├── preprocessing_utils.py # Dataset prep, transforms, loaders, visualization
├── implementation.ipynb # Exploratory + training notebook (MLP focus)
├── presentation.ipynb # Final report + results discussion
├── notebooks/ # Additional notebooks for display in the website
├── checkpoints/ # Saved model weights (per config)
├── metrics/ # JSON + CSV run metrics
├── plots/ # Loss/accuracy curves & confusion matrices
├── data/ # Prepared splits + raw CSV
└── LICENSE # GPLv3 license
- Convolutional baselines (CNN) with non‑flattened transforms.
- Calibration analysis (reliability diagrams, ECE).
- Automated hyperparameter search (Optuna / Ray Tune).
- Model ensembling across top runs.
- Export for mobile / ONNX runtime inference.
This project is distributed under the terms of the GNU General Public License v3.0 (GPL‑3.0). See the LICENSE file for full details.