A small educational MNIST neural-network implementation in C with:
- a minimal fully-connected network (forward/backward) in layer.c/h and mnist_model.*
- a CLI trainer/tester (train)
- a Raylib-based desktop demo (main) where you can draw digits
- a WebAssembly web demo (webapp/) built with Emscripten
- Train on the MNIST dataset and save/load parameters (weights.bin)
- Real-time desktop drawing demo using Raylib
- Browser demo (nn.js / index.html) with preprocessing and WASM inference
- gcc, make, curl, gunzip
- raylib (for the desktop demo)
- Emscripten (emcc) to build the web demo
-
Fetch the MNIST dataset: ./download_mnist.sh
-
Build native tools: make
-
Train and save parameters (example): ./train save weights.bin # trains for a few epochs and writes weights
-
Run tests against saved parameters: ./train load weights.bin
-
Run the Raylib drawing demo (desktop GUI): ./main weights.bin
-
Build the WebAssembly demo (requires emscripten): make nn.js (serve the
webapp/directory with a static server, e.g.) python3 -m http.server --directory webapp 8000 then open http://localhost:8000/
- layer.c / layer.h — low-level layer implementation (forward/backward)
- mnist_model.c / mnist_model.h — model wrapper, IO (load/save), train/test helpers
- train.c — CLI for training/saving/loading/testing
- main.c — Raylib desktop demo (draw digits & predict)
- download_mnist.sh — downloads and unpacks MNIST into
data/ - Makefile — targets:
make(native build),make train,make nn.js(emscripten) - webapp/ — browser UI, nn.js (WASM bootstrap), index.html, index.js
- todo.txt — developer TODOs and cleanup notes
- The model saved format is a raw binary dump (weights then biases). Use
./train saveto produce a compatible weights file. - Raylib demo links against system raylib; ensure your platform has it installed (package name often
libraylib-dev/raylib). - The web demo embeds
weights.binvia the Emscripten--embed-fileflag in the Makefile.
