PyTroch 1.0 preview - LOADING A PYTORCH MODEL IN C++
Details refer to: https://shiftlab.github.io/pytorch_tutorials/advanced/cpp_export.html
Main requires: PyTroch 1.0, opencv, cmake
CONVERTING YOUR PYTORCH MODEL TO TORCH SCRIPT and SERIALIZING YOUR SCRIPT MODULE TO A FILE
- run
python tracing.py
and getmodel.pt
LOADING YOUR SCRIPT MODULE IN C++ and EXECUTING
-
Download LibTorch here and unzip
-
Cmake
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/Users/hankai/code/cpp-pytorch/libtorch ..
make
- Run demo
./example-app ../model.pt ../dog.png ../synset_words.txt
Input image and predicted label: n02108422 bull mastiff
, bingo!