Hi all,
I converted and saved “maskrcnn_resnet50_fpn” model to script model. But when trying to load this model in c++, it fails without any error.
torch : 1.10.2+cu113
torchvision : 0.11.3+cu113
LibTorch: libtorch-win-shared-with-deps-1.10.2+cu113
OS: Windows10
Python Code -
kwargs = {"trainable_backbone_layers": None}
checkpoint_name = "checkpoint.pth"
model = torchvision.models.detection.__dict__["maskrcnn_resnet50_fpn"](pretrained=False, num_classes=5, **kwargs)
model.load_state_dict(torch.load(checkpoint_name)['model'])
model.eval()
script_model = torch.jit.script(model)
torch.jit.save(script_model, 'maskrcnn_ts.pt')
c++ code -
#include <torch/torch.h>
#include<torch/script.h>
#include <iostream>
#include <memory>
int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}
std::string model_pt_name = argv[1];
std::cout << "Loading Model " << model_pt_name << "\n";
torch::jit::script::Module module = torch::jit::load(model_pt_name);
/* try {*/
// Deserialize the ScriptModule from a file using torch::jit::load().
std::cout << "Loaded Model\n";
/* }
catch (const c10::Error& e) {
std::cerr << "error loading the model\n";
return -1;
}*/
std::cout << "ok\n";
}
C++ project is build in Release mode.
cmd : LibTorchScriptProject.exe maskrcnn_ts.pt
This fails in the step " torch::jit::script::Module module = torch::jit::load(model_pt_name);" without any error message. Can you please advise what is the issue here.