mnist-classify/README.md
2025-05-22 19:35:24 +00:00

53 lines
No EOL
1.5 KiB
Markdown

# MNIST classifier in C++
This is a simple MNIST classifier I wrote for school in C++ from scratch.
## Compiling and Running
1. Download the MNIST dataset from <https://archive.org/download/mnist-dataset>
2. 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)
3. Extend the MNIST dataset using `mnist-ext` by `cp -r mnist-ext/* MNIST_Dataset/trainingSet`
4. `make clean && make && ./mnist-classify`
5. 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:
1. Width and height are both 28 pixels, **press "save canvas" before anything**.
2. Set the brush size to 2
3. Draw your number :)
... or open the [ppm.html file](ppm.html) in your browser.
### Cross-Compiling to Windows
```sh
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:
```sh
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build . -j4 --config Release
```
Its very recommended to turn on the minimal logging option on for Windows users.