Skip to content

Latest commit

 

History

History
104 lines (56 loc) · 1.57 KB

File metadata and controls

104 lines (56 loc) · 1.57 KB

ResNet

ResNet model with C++/Python language.

C++

1. Download libtorch

Download libtorch (PyTorch library for C++), extract.

  • Without CUDA (CPU)
wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip
unzip libtorch-shared-with-deps-latest.zip
  • With CUDA (CPU+GPU)
wget https://download.pytorch.org/libtorch/cu102/libtorch-shared-with-deps-1.5.1.zip
unzip libtorch-shared-with-deps-1.5.1.zip

2. Build

Build ResNet with cmake.

cd cpp
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch ..
cmake --build . --config Release

3. Download MNIST dataset

Download MNIST dataset from website and locate to mnist directory.

4. Train

Run ResNet model to train.

./train -m saved_model

Trained model will be saved to saved_model directory.

5. Predict

Using trained model, predict a class where the sample image (digit.png) belongs.

./predict -i ../../data/digit.png -m saved_model

Python

1. Install pytroch

Install pytorch package.

pip install pytorch

2. Train

Run ResNet model to train.
MNIST data will be downloaded to mnist directory within the Python program.

cd python
python train.py -m saved_model

Trained model will be saved to saved_model directory.

3, Predict

Using trained model, predict a class where the sample image (digit.png) belongs.

python predict.py -i ../data/digit.png -m saved_model