How can I read the .pt file(which save by python script not by jit script) in C++ by torch::load from libtorch?

How can I read the .pt file(which save by python script) in C++ by torch::load from libtorch?

At first, I have trained a model in python, and have already saved the weight file in .pt format.
So is it possible I read this .pt file in C++ using libtorch with torch::load?

Thanks

It’s currently not possible to read .pt file saved by Python script, because Python script’s torch.save method uses pickling and it’s not understood by C++.

In order to load a pre-trained model into libtorch, the model should be written in TorchScript, saved with model.save(filename) and loaded into libtorch with torch::jit::load().

1 Like

Thanks a lot, I have loaded the .pt file from torch.jit. Script into my C++ model, but still need to do few changes. Anyway that works, thanks for you attention.

1 Like

Is there any plan to support loading a model without translate it into TorchScript?