How to load state_dict to Module in libtorch C++ for Inference

Hi, So I have use case of using our Pytorch model in C++, I have

  • Model Architecture in Pytorch (Python code)
  • .pth file

I’m really new to this, I have seen torch script and tracing. I’m also confused on what to use and also if I use any of this, how can I accommodate my ‘.pth’ file in that.

The tutorial way of moving models to C++ for inference is through tracing/scripting the model. The main alternative would be to re-create the model in C++ using the nn API there and then loading the weights (e.g. torchvision does that for the conv net models for testing).

Best regards