How to load state_dict to Module in PyTorch C++


Hey there,

i have a model trained in Python/PyTorch and saved it via "{‘model’, model.state_dict()}). The task is to load this “.pth.tar”-file into a C++/PyTorch module and apply it to the same architecture.
Is there a similar method to the Python/PyTorch mehtod "model.load_state_dict(torch.load(“model.pth.tar”)) in C++/PyTorch?

Thanks a lot!

By the way, does a serializated ScriptModule (“”)) also saves the state of the module or only the architecture itself?

Thanks again!

(Thomas V) #2

So the answer here

is yes. Does that also solve the need for loading the state dict?
I cannot praise the export to c++ tutorial enough.

Best regards