Rust NN: an educational Neural Network framework in Rust
Features include:
- Ergonomic APIs for building and training your networks.
- Predefined optimizer methods and activation functions, as well as the ability to add your own via implementing a trait.
- Fully customizable GUI via egui for seeing your network during training, including some prebuilt GUIs.
Examples
For more detailed examples, look at the examples directory.
- Examples directory. Featured examples:
- adder_gui -- a simple example of creating a custom training GUI to train a neural network to add numbers
- learn_image -- a more involved example for training a neural network to upscale and interpolate images
Note: Running in release makes training drastically faster, i.e. do cargo run --release
.
Minimal example
Here is how you'd create a model that learns to behave like an XOR gate.
let mut net = new;
net.add_layer;
let inputs = from_array.into;
let targets = from_array.into;
let learning_rate = 10e-0;
let epochs = 10_000;
// Initialize the optimizer to log the error at each epoch
let optim = new.with_log;
optim.train;
let fin = net.mean_squared_error.unwrap;
println!;
let res = net.run_batch.unwrap;
for in inputs.to_vec.into_iter.zip
To make the optimizer display graph the error at each epoch, you can do this:
optim.;
Here, NNGui
is a predefined struct implementing the Visualizer
trait that allows the optimizer to spawn and asynchronously update a GUI (meaning performance shouldn't be affected).