• Stars
    star
    164
  • Rank 228,679 (Top 5 %)
  • Language
    C++
  • Created almost 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A bite of cpp api in PyTorch-1.0

cpp-pytorch

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

STEP 1

CONVERTING YOUR PYTORCH MODEL TO TORCH SCRIPT and SERIALIZING YOUR SCRIPT MODULE TO A FILE

  • run python tracing.py and get model.pt

STEP 2

LOADING YOUR SCRIPT MODULE IN C++ and EXECUTING

  1. Download LibTorch here and unzip

  2. Cmake

mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/Users/hankai/code/cpp-pytorch/libtorch ..
make
  1. Run demo
./example-app ../model.pt ../dog.png ../synset_words.txt

Input image and predicted label: n02108422 bull mastiff, bingo!