An experimental Neural Network trainer/visualizer in Rust

Overview

DeepRender

An experimental Neural Network trainer/visualizer in Rust

Try it on your browser! https://msakuta.github.io/DeepRender/

Training on a function

A neural network is a universal function approximator. Therefore, you can fit it to any function, including sine wave, given enough neurons.

Training process:

An example of training on an image

You can train the network to imitate an image!

An example of training 3D renderer

Training process:

Training process

Result:

Result

What's this?

This project attempts to implement a neural network trainer and visualizer with a GUI using eframe/egui without using any of the deep learning libraries. Even the matrix operations are implemented from scratch. As such, this project is not expected to work efficiently.

There are 4 models to train:

  • XOR logical gate
  • sinusoidal function
  • Synthetic image (2D function field)
  • An image
  • A 3D scene rendered with ray tracing renderer (ray-rust)

You can switch the model, activation functions, the network architecture and the descent rate in real time.

See this document for more details about the theoretical background.

This project is inspired by this video series, where deep learning framework is implemented in plain C (if you can do it in C, why not in Rust?): https://youtu.be/PGSba51aRYU

How to build

Install Rust.

cargo r

How to build Wasm version

You can build the application to WebAssembly and run on the browser.

  • Install wasm-pack
  • Install trunk by cargo install trunk
  • Run trunk serve for development server, or
  • Run trunk build --release for release build in eframe/dist

Note that you cannot use File Image as the fit model with Wasm build. Please use local build if you want that feature (it is faster to train on local build anyway).

You might also like...
n2 is a library implementation of a feedforward, backpropagation artificial neural network.

n2 is a library implementation of a feedforward, backpropagation artificial neural network. Usage Add the following to the [dependencies] section o

A light wheight Neural Network library with a focus on ease of use and speed.

Smarty Pants This goal of this library is to: Produce NeuralNetworks that will always give the same result when given the same input. Provide methods

A neural network model that can approximate any non-linear function by using the random search algorithm for the optimization of the loss function.

random_search A neural network model that can approximate any non-linear function by using the random search algorithm for the optimization of the los

Build neural network models in Cairo 1.0

Explore ML in Cairo 1.0 Build neural network models in Cairo 1.0 to perform inference. The calculations are performed using i33 values, and the outcom

The CBNF neural network header format.

cbnf The CBNF neural network header format. What is CBNF? CBNF is a neural network header format for use with efficiently updatable neural networks fo

GBS/LSDj visualizer based on SameBoy and FFmpeg
GBS/LSDj visualizer based on SameBoy and FFmpeg

GBPresenter GBPresenter is a tool I wrote to generate visualizations of GameBoy chiptunes, based on SameBoy, FFmpeg, and Slint. The visualization desi

Neural networks in Rust

deeplearn-rs Deep learning in Rust! This is my first shot at this. It's mostly just a proof of concept right now. The API will change. Status We have

Rust implementation of real-coded GA for solving optimization problems and training of neural networks
Rust implementation of real-coded GA for solving optimization problems and training of neural networks

revonet Rust implementation of real-coded genetic algorithm for solving optimization problems and training of neural networks. The latter is also know

Compile-time creation of neural networks with Rust

GAMMA Compile-time creation of neural networks with Rust Description This is for now just a showcase project of what can be done with const generics i

Comments
  • Stateful samplers

    Stateful samplers

    Sampler trait

    Now we can split the traning data into batches and render the GUI in between each of them, thanks to the sampler trait implemented as state machines.

    pub(crate) trait Sampler {
        fn sample(&mut self, train_batch: TrainBatch, batch_size: usize) -> Matrix;
        fn full(&self) -> &Matrix;
    }
    

    MatrixSampler struct

    The MatrixSampler struct which implements this trait has internal state that can make progress every sample. It also provides with full method, which is used to evaluate global loss function (which is not necessarily evaluated every batch because evaluating the whole training set's loss can be time consuming).

    The effect of this is that the GUI won't freeze for a large training set. Previously, we run the whole training set every frame, but it can be much slower than 16ms and we won't achieve 60fps. Now you can adjust the number of batches to train per frame in the control panel.

    image

    MatrixSampler struct

    There is another implementor of Sampler which is RaytraceSampler. This sampler does not use pre-allocated sample array. It uses truly random rays every time it samples. It can make the scene rendering smoother because it is trained in actually random samples in between pixels and angle units, unlike pre-sampled raster images.

    You can see the result:

    DeepRender3DResult6

    The reference image on the left is not very accurate anymore because the network is not trained on this pixelated image, but putting a large image here is costly in itself (because we need to evaluate the value over the whole 3D image to calculate the loss).

    opened by msakuta 0
Owner
Masahiro Sakuta
Masahiro Sakuta
Simple neural network library for classification written in Rust.

Cogent A note I continue working on GPU stuff, I've made some interesting things there, but ultimately it made me realise this is far too monumental a

Jonathan Woollett-Light 41 Dec 25, 2022
Rust wrapper for the Fast Artificial Neural Network library

fann-rs Rust wrapper for the Fast Artificial Neural Network (FANN) library. This crate provides a safe interface to FANN on top of the low-level bindi

Andreas Fackler 12 Jul 17, 2022
A neural network, and tensor dynamic automatic differentiation implementation for Rust.

Corgi A neural network, and tensor dynamic automatic differentiation implementation for Rust. BLAS The BLAS feature can be enabled, and requires CBLAS

Patrick Song 20 Nov 7, 2022
Simple Neural Network on rust

Simple Artificial Neural Network A crate that implements simple usage of dense neural networks. Instalation Add this to your dependencies on Cargo.tom

null 6 Jul 1, 2022
Machine learning Neural Network in Rust

vinyana vinyana - stands for mind in pali language. Goal To implement a simple Neural Network Library in order to understand the maths behind it. This

Alexandru Olaru 3 Dec 26, 2022
A gpu accelerated (optional) neural network Rust crate.

Intricate A GPU accelerated library that creates/trains/runs neural networks in pure safe Rust code. Architechture overview Intricate has a layout ver

Gabriel Miranda 11 Dec 26, 2022
Neural network implementations from scratch in Rust.

Neural Network from Scratch Neural network implementations from scratch in Rust. Setup & Run Dataset used is mnist. Download the 4 archives and extrac

Mohammad Rahhal 6 Dec 29, 2022
A fun, hackable, GPU-accelerated, neural network library in Rust, written by an idiot

Tensorken: A Fun, Hackable, GPU-Accelerated, Neural Network library in Rust, Written by an Idiot (work in progress) Understanding deep learning from t

Kurt Schelfthout 44 May 6, 2023
A neural network crate

RustNN An easy to use neural network library written in Rust. Crate Documentation Description RustNN is a feedforward neural network library. The libr

Jack Montgomery 316 Dec 29, 2022
SelfOrgMap 5 Nov 4, 2020