Pytorch weight(.pth) port to Libtorch weight(.pt)

Hello guys.

I used to use C++ when I code something.

So, I prefer to make Libtorch(frontend version, not torch::jit::script) to implement deep learning.
(I make Libtorch frontend model refer to original python(Pytorch) code, and make all Libtorch frontend model’s submodule names are same with Pytorch model’s submodule.)

I have trained model without pre-trained, if I use my own dataset.

But, now I would like to use pre-trained weight files, such as what was trained with KITTI dataset.

Most of pre-trained is as “.pth”(Pytorch), but I want to port it to “.pt” that can be loaded with Libtorch frontent model.
(e.g., torch::load(model, “”):wink:

In figure, left is Pytorch version weight, right is Libtorch frontend version weight, configurations are different, but they are same at layer counts and submodule name.

Please let me know how to convert .pth to .pt(Please note It isn’t torch::jit:script module based).


How are you saving the model in PyTorch. Are you saving the entire module or just the state_dict()?
I think you might want to do` so you don’t get that code directory.

I am using as at Python, but they don’t have constant.pkl in pth file.

It outputs “terminate called after throwing an instance of ‘c10::Error’ what(): PytorchStreamReader failed locating file constants.pkl: file not found”, when I load .pth using Libtorch frontend(torch::load()).