I know detail about how to save torchscript model using python, and load it with c++ from the doc: link.
But how to save torchscript using cpp?I should train my model using c++, but I don’t find any detail about it in document.
Thanks!
I know detail about how to save torchscript model using python, and load it with c++ from the doc: link.
But how to save torchscript using cpp?I should train my model using c++, but I don’t find any detail about it in document.
Thanks!
Hi.
You can refer to the repository below to do what you want.
Created by referring torchvision.
Hi, Thanks for your reply.
But I should train model with C++ and save the model as JIT script. The reason why I should save model as JIT script is that the inference code can’t access to model structure(the model defination class). Thus, I should find a way to save model as JIT script using C++.
However, the code you provide above should pass Model
instance as parameter, so It doesn’t meet my need.
I don’t know
Is it to avoid exposing the model structure in inference?
It is one aspect. On the other hand, the Script Model has high-performance.
Hi, have you solved it? I have the same problem, and I try to trian the script model in C++, but it not works, could you please give me some help while you have train it successfully?thanks
Hi, I found that both torchscript
and torch::nn::Module
model file can be loaded with torch::load(model, "model_file.pt");
. It isn’t nesscery to save torchscript model in cpp while you load torchscript model to nn::Module and train it.
@yf225 I am sorry to disturb, Could u give me a little hint about whether libtorch could save torchscript model using cpp or not. Thank you so much!
@SixerWang By “saving a TorchScript model in C++”, do you mean one of the following:
Thank you very much for your reply. My situation is the second one. I will change my training process.Thank you!
Hi, have you solved the problem?