iamhankai / cpp-pytorch

A bite of cpp api in PyTorch-1.0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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!

About

A bite of cpp api in PyTorch-1.0


Languages

Language:C++ 93.2%Language:C 4.3%Language:Cuda 1.4%Language:CMake 1.1%Language:Python 0.0%Language:Objective-C 0.0%