An MNIST dataset classifier neural network in C++ without any libraries :) (Machine Learning stuff for school)
|
|
||
|---|---|---|
| mnist-ext | ||
| presentations | ||
| src | ||
| tests | ||
| .clang-format | ||
| .editorconfig | ||
| .gitignore | ||
| CMakeLists.txt | ||
| CONTRIBUTING.md | ||
| CONTRIBUTORS.md | ||
| LICENSE | ||
| Makefile | ||
| model-traning-stats-98.3p.txt | ||
| modelis.txt | ||
| mokymo_statistika.gif | ||
| ppm.html | ||
| README.md | ||
| toolchain-mingw64.cmake | ||
| visualise.py | ||
MNIST classifier in C++
This is a simple MNIST classifier I wrote for school in C++ from scratch.
Compiling and Running
- Download the MNIST dataset from https://archive.org/download/mnist-dataset
- Convert all images in
MNIST_Dataset/trainingSet/*to the PPM P6 format:
for d in ./*; do
cd "$d"
parallel -j 8 'ffmpeg -y -i {} {.}.ppm && rm {}' ::: *.jpg
cd ..
done
(or something like that, parallel makes it a lot faster)
- Extend the MNIST dataset using
mnist-extbycp -r mnist-ext/* MNIST_Dataset/trainingSet make clean && make && ./mnist-classify- watch the magic happen :)
You may use the pre-built model at modelis.txt with 99% or so accuracy. (sorry for the unoptimised code, I only had time til today's evening)
If you want to classify own images, feel free to use the https://ari.lt/ppm tool to draw your own, ensure:
- Width and height are both 28 pixels, press "save canvas" before anything.
- Set the brush size to 2
- Draw your number :)
... or open the ppm.html file in your browser.
Cross-Compiling to Windows
rm -rf build
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchain-mingw64.cmake ..
cmake --build .
Compiling on Windows using MSVC
Open the Developer Command Prompt and navigate to the project's root directory, then execute the following commands:
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j4 --config Release