So I have a pretrained pytorch model, I have saved both the model and the parameters just in case, but I need to use this model in C or C++ code, anybody know how I can do that?
Thanks a lot.
So I have a pretrained pytorch model, I have saved both the model and the parameters just in case, but I need to use this model in C or C++ code, anybody know how I can do that?
Thanks a lot.
Try pytorch 1.0, which include a c++ library. The model could be exported to torch script format and be loaded in C++, check here https://pytorch.org/tutorials/advanced/cpp_export.html
If you are using Ubuntu, try pytorch package in PPA of ppa:nnstreamer/ppa. In this Ubuntu pytorch package, there are header files and pkgconfig (.pc) file that helps building C/C++ programs using pytorch. If you want more simple ways to invoke pytorch/caffe2 models from C/C++ program, you may use C/API of nnstreamer or approach nnstreamer w/ GStreamer API as well.
To install nnstreamer or C-friendly pytorch (or tensorflow), use PPA by:
$ sudo add-apt-repository ppa:nnstreamer/ppa
$ sudo apt-get update
$ suto apt-get install ${whateveryouwant}
Candidates for ${whateveryouwant}: nnstreamer, nnstreamer-dev, nnstreamer-pytorch
If you want to access pytorch directly from your C code without using nnstreamer, you may refer to pytorch-wrapper of nnstreamer at: https://github.com/nnsuite/nnstreamer/blob/master/ext/nnstreamer/tensor_filter/tensor_filter_pytorch_core.cc