An interactive, from-scratch implementation of a multilayer perceptron (MLP) neural network in Jai, with real-time DX11 visualization, training, and inference. Developed as a personal learning project while following the excellent 3Blue1Brown neural network series. Since I wrote this while learning myself, the code should be fairly easy to follow with the videos but isn’t meant to be optimal or a reference implementation.
-
Neural Network Implementation
- Forward and backpropagation from scratch
- Customizable layer configurations and activation functions
- MSE and cross-entropy loss support
-
Dataset Support
- Supports MNIST (digits) and EMNIST balanced (digits + characters) datasets
- Save/load models at runtime
- Pre-trained examples included for both datasets
-
Real-time Visualization
- Interactive network structure and activation display
- Customizable themes and rendering options
- Live accuracy tracking
At the repository root:
jai main.jai
./main
There are significant performance benefits to building with the VERY_RELEASE configuration in Jai, which does a better job of auto-vectorizing some of the loops (even though they were written to try and trigger this).
The repository includes pre-trained networks ready for immediate use. To train your own models:
From Kaggle MNIST CSV:
- Download
mnist_test.csvandmnist_train.csv - Copy both files to the
datadirectory
From Kaggle EMNIST:
- Download
emnist_balanced_train.csvandemnist_balanced_test.csv - Copy both files to the
datadirectory
Click 'Rebuild and train' in the GUI to rebuild for the configuration specified on the GUI, or 'Continue training' to continue running training on the current network.
MIT
Third party:
- SDL2 - Licensed under zlib license
- Dear ImGui - Licensed under MIT license
- Contains modified snippets from the Jai standard library
See respective library licenses for full terms.
