Skip to content

HughClub/MNIST-libtorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MNIST with libtorch

A simple repo for beginner to train on MNIST with libtorch(cpu version)

libtorch

  1. Download libtorch from https://pytorch.org/get-started/locally/ or wget the latest nightly build.
  2. unzip your libtorch and set the environment variable YOUR_LIBTORCH_FOLDER to the path of the unzipped folder.

editor hint

For VSCode

You should set the includePath for VSCode to search the include headers.

YOUR_LIBTORCH_FOLDER="" # fill it
LIBTORCH_INCLUDE="${YOUR_LIBTORCH_FOLDER}/include"
DEEPER_LIBTORCH="${LIBTORCH_INCLUDE}/torch/csrc/api/include"

Create .vscode/c_cpp_properties.json and set includePath. You can take the following as an example

{
    "configurations": [
        {
            "name": "libtorch",
            "includePath": [
                "./libtorch/include",
                "./libtorch/include/torch/csrc/api/include/"
            ]
        }
    ],
    "version": 4
}

training

There are three relative files.

  • main.cpp: show simple standard training pipeline here
  • net.hpp: the file where the real model hides
  • utils.hpp: some utils

For simplicity, I don't divide the headers into .h in the include and .cpp in the src and compile they into .a or .so files.

You can build and run your models like:

mkdir build
cd build
cmake ..
make
cd ..
./build/mnist # It depends on what you specify your data path in your code

result

Without specific seed, cmd:./build/mnist 64 1e-3 128 150 could achive a test accuracy of 0.8726 with a model size of 216kB.

About

A simple implementation on MNIST with libtorch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published