https://github.com/terror/mnist
A neural network
https://github.com/terror/mnist
Last synced: 2 months ago
JSON representation
A neural network
- Host: GitHub
- URL: https://github.com/terror/mnist
- Owner: terror
- License: cc0-1.0
- Created: 2023-04-17T18:14:03.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T19:08:23.000Z (over 1 year ago)
- Last Synced: 2025-07-14T07:15:22.061Z (6 months ago)
- Language: Rust
- Size: 13.5 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
Awesome Lists containing this project
README
## mnist
[](https://github.com/terror/mnist/actions/workflows/ci.yml)
**mnist** is a neural network written from scratch with the goal of being able to
recognize handwritten digits, written in pure Rust with minimal dependencies
used in the training process.
### Usage
Train the model and make predictions using saved weights.
```
Usage: mnist
Commands:
app Run an interactive GUI application
predict Predict the class of a new instance
train Train the model
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
```
### Training
Below are the results from training on the standard MNIST dataset. This used a
learning rate of `0.1`, a batch size of `128`, and trained for `100` epochs. These
values are configurable via the `train` subcommand.
```
Dataset loaded successfully:
Training images: 60000
Training labels: 60000
Test images: 10000
Test labels: 10000
[01:24:29] ======================================== 100/100 Epochs Training complete
Final accuracy: 97.16%
Saved weights to weights.json
```
### Inference
You can use the `predict` subcommand with pre-defined weights to make
predictions on new data.
```bash
cargo run -- predict --weights weights.json --image samples/2.png
```
### Live drawing
You can spawn a GUI app for live drawing/inference using the CLI as well:
```
cargo run -- app --weights weights.json
```
The app is built using [`egui`](https://www.egui.rs/) and re-uses a neural net
with stored weights for making live predictions.
### Prior Art
Wrote this while reading [**Make Your Own Neural Network**](https://www.amazon.ca/Make-Your-Own-Neural-Network/dp/1530826608) by Tariq Rashid.