This code template is a simple neural network implementation using the tch (Torch) library to perform digit classification on the MNIST dataset. The MNIST dataset consists of 28x28 grayscale images of handwritten digits (0 to 9). The goal is to train a neural network to correctly classify these digits.
You can use this template to build your Neural Network projects with Rust β Torch.
Training the neural network:
Download the project from Git:
$ git clone https://github.com/NeuroQuestAi/rust-nn.git && cd rust-nn
The tests were done using a Linux π§ machine.
- Need to have installed build-essential;
- You need to have Rust installed.
The torch version used was version v2.0.0. You can download it directly from the website https://pytorch.org/get-started/locally/, or follow the procedures below via the command line. Package used: (libtorch-cxx11-abi-shared-with-deps-2.0.0+cu118.zip).
In the root folder of the project, create a libs directory in the root of the project:
$ mkdir libs
Now download the Torch lib and unzip it:
$ curl -L \
"https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.0.0%2Bcu118.zip"\
> libs/libtorch-cxx11-abi-shared-with-deps-2.0.0+cu118.zip
The package is about 2.3 GB. Now unzip the file:
$ unzip libs/libtorch-cxx11-abi-shared-with-deps-2.0.0+cu118.zip -d libs/
Now it is necessary to export the environment variables:
$ export LIBTORCH=`pwd`/libs/libtorch
$ export LD_LIBRARY_PATH=`pwd`/libs/libtorch/lib:${LD_LIBRARY_PATH}
Create the data directory:
$ mkdir data
Now let's download the MNIST datasets:
$ curl -L "https://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz" > data/train-images-idx3-ubyte.gz
$ curl -L "https://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz" > data/train-labels-idx1-ubyte.gz
$ curl -L "https://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz" > data/t10k-images-idx3-ubyte.gz
$ curl -L "https://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz" > data/t10k-labels-idx1-ubyte.gz
Unzip all files:
$ gunzip data/*.gz
With rust already installed on your machine, just build:
$ cargo build
And run:
$ cargo run
- Ederson Corbari π½