Skip to content

A simple neural network 🧠 implementation using the tch (Torch) πŸ€– library with Rust πŸ¦€

Notifications You must be signed in to change notification settings

NeuroQuestAi/rust-nn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

A Simple Neural Network 🧠

Powered by NeuroQuestAI rustc

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.

Project ☁️

Training the neural network:

running

Download the project from Git:

$ git clone https://github.com/NeuroQuestAi/rust-nn.git && cd rust-nn

Requirements πŸ› οΈ

The tests were done using a Linux 🐧 machine.

Torch πŸ’»

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}

Datasets πŸ’»

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

Build and Running πŸš€

With rust already installed on your machine, just build:

$ cargo build

And run:

$ cargo run

Authors πŸ‘¨β€πŸ’»

About

A simple neural network 🧠 implementation using the tch (Torch) πŸ€– library with Rust πŸ¦€

Topics

Resources

Stars

Watchers

Forks

Languages