A C++17 Fashion-MNIST classifier project with:
- an in-house neural network implementation,
- a KNN baseline with OpenMP acceleration, and
- both CLI and interactive TUI workflows.
- In-house neural network (no external ML runtime)
- KNN with distance-weighted voting (optional uniform voting)
- Robust dataset/model/input validation
- Interactive terminal UI (
./build/tui) - Top-k probability output for predictions
ImageClassifier/
├── src/
│ ├── apps/ # train / predict / tui entrypoints
│ ├── classifiers/ # neural_net + knn implementations
│ └── core/ # dataset loader + classifier base logic
├── include/ # public headers
├── scripts/
│ ├── download_fashion_mnist.sh
│ └── preprocess.py
├── data/ # local datasets and sample inputs
├── models/ # generated model files
├── Makefile
├── CMakeLists.txt
└── README.md
- C++17 compiler (
g++orclang++) - OpenMP (optional but recommended for KNN)
- Python 3 + Pillow + NumPy (required only when using non-
.txtimage inputs like.png/.jpg)
git clone https://github.com/udaykiriti/ImageClassifier.git
cd ImageClassifier
./scripts/download_fashion_mnist.sh
make -j4
./build/tuimake train
make predict
make tui
make # builds all
make clean # remove build outputs and generated models# Neural network (default)
./build/train
# Neural network with explicit hyperparameters
./build/train --model nn --train 5000 --test 1000 --epochs 15 --batch 64 --hidden 256 --lr 0.01 --l2 0.0001 --seed 42
# KNN
./build/train --model knn --train 2000 --test 500 --k 5
# KNN with uniform voting
./build/train --model knn --train 2000 --test 500 --k 5 --uniform-knnTrain flags:
| Flag | Description | Default |
|---|---|---|
--model |
nn or knn |
nn |
--train |
Training samples | 2000 |
--test |
Test samples | 500 |
--epochs |
NN epochs | 10 |
--batch |
NN batch size | 32 |
--hidden |
NN hidden size | 128 |
--lr |
NN learning rate | 0.01 |
--l2 |
NN L2 regularization | 1e-4 |
--seed |
NN random seed | 42 |
--k |
KNN neighbors | 3 |
--uniform-knn |
Use uniform voting (disable distance weighting) | off |
# Basic prediction
./build/predict
# Show ASCII image
./build/predict --image data/image.txt --show
# Predict directly from PNG/JPG (auto-preprocessed)
./build/predict --image data/image.png --topk 3
# Compare against known class
./build/predict --image data/image.txt --label 8 --show
# Show top-k probabilities
./build/predict --image data/image.txt --topk 3Predict flags:
| Flag | Description | Default |
|---|---|---|
--image |
Input path (.txt or image file like .png/.jpg) |
./data/image.txt |
--model |
Model file path | ./models/neural_net.model |
--label |
True class id (0-9) | omitted |
--topk |
Show top-k probabilities | 0 |
--show |
Print ASCII image | off |
Image text format:
- exactly 784 values (28x28)
- values accepted in either
0..255or normalized0..1 - non-
.txtfiles are auto-preprocessed viascripts/preprocess.py- automatically inverts colors if light background is detected (Fashion-MNIST is white-on-black)
- if preprocessing dependencies are missing:
pip install pillow numpy
./build/tuiMenu-driven options:
- Train / Evaluate model
- Predict from image
- Show class labels
| ID | Class |
|---|---|
| 0 | T-shirt/top |
| 1 | Trouser |
| 2 | Pullover |
| 3 | Dress |
| 4 | Coat |
| 5 | Sandal |
| 6 | Shirt |
| 7 | Sneaker |
| 8 | Bag |
| 9 | Ankle boot |
- Datasets and trained models are not tracked as source artifacts.
- If
predictreports missing/unsupported model, run./build/train --model nn ...once to regeneratemodels/neural_net.model. - If
predictresults are poor for your own images, ensure the background is dark (or rely on auto-inversion inpreprocess.py). - If dataset files are missing, run
./scripts/download_fashion_mnist.sh.
MIT. See LICENSE.
- Fashion-MNIST: https://github.com/zalandoresearch/fashion-mnist