https://github.com/emsar69/mnist-ai-without-external-ai-libraries
A pure C++ implementation of an MNIST digit classifier without using external machine learning libraries. This project demonstrates how to build a simple neural network for the MNIST dataset.
https://github.com/emsar69/mnist-ai-without-external-ai-libraries
ai c classification cpp machine-learning mnist
Last synced: 2 months ago
JSON representation
A pure C++ implementation of an MNIST digit classifier without using external machine learning libraries. This project demonstrates how to build a simple neural network for the MNIST dataset.
- Host: GitHub
- URL: https://github.com/emsar69/mnist-ai-without-external-ai-libraries
- Owner: emsar69
- License: gpl-3.0
- Created: 2025-05-07T12:38:25.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-08T16:29:04.000Z (about 1 year ago)
- Last Synced: 2025-05-11T11:58:27.552Z (about 1 year ago)
- Topics: ai, c, classification, cpp, machine-learning, mnist
- Language: C++
- Homepage:
- Size: 4.7 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# emsar69/MNIST-AI-Without-External-AI-Libraries
Artifical Intelligence number recognization by images — using no AI libraries
## Quick Start
> Make sure you have installed cmake and C++ compiler.
### Example Dataset
Use the following structure of handwritten digits dataset:

Rename your dataset folder to `mnist_dataset` or edit the code in `Main.cpp`:
```cpp
load_dataset(inputs, targets, "mnist_dataset", 3000); // Last parameter (3000) means how much data per number.
```
### Building With CMake
In project directory:
```shell
mkdir build
cd build
```
Using MinGW
```shell
cmake -G "MinGW Makefiles" ..
```
Using Ninja
```shell
cmake -G "Ninja" ..
```
Using Clang/Unix Based
```shell
cmake -G "Unix Makefiles" ..
```
### Example output
Example neural network trained with 30k different image/label pairs output:
```log
> .\MNIST_AI.exe
[DEBUG][14:51:03] -> Dataset Loaded: 30000
[DEBUG][14:51:03] -> Training.
[DEBUG][14:51:12] -> Epoch 1 done. Train Accuracy: 91.29% | Test Accuracy: 95.07% | Loss: 0.28
[DEBUG][14:51:20] -> Epoch 2 done. Train Accuracy: 96.38% | Test Accuracy: 95.87% | Loss: 0.12
[DEBUG][14:51:30] -> Epoch 3 done. Train Accuracy: 97.73% | Test Accuracy: 96.80% | Loss: 0.08
[DEBUG][14:51:39] -> Epoch 4 done. Train Accuracy: 98.64% | Test Accuracy: 97.13% | Loss: 0.05
[DEBUG][14:51:48] -> Epoch 5 done. Train Accuracy: 99.15% | Test Accuracy: 97.47% | Loss: 0.03
> example.png
[DEBUG][14:52:43] -> 6.16999e-09 1.08969e-05 5.33723e-05 5.21402e-06 0.999413 3.98535e-08 5.83457e-06 0.000229053 6.17532e-07 0.000281614
[DEBUG][14:52:43] -> Which means, Neural network thinks this is a 4 with 100% confidence.
```
# License
[GNU GENERAL PUBLIC LICENSE 3.0](LICENSE)