biubug6 / Pytorch_Retinaface

Retinaface get 80.99% in widerface hard val using mobilenet0.25.
MIT License
2.6k stars 764 forks source link

load the model with libtorch in c++, "The file not found: retinaface_mobilenet/model.json" #61

Open xscjun opened 4 years ago

xscjun commented 4 years ago

Hi,Thanks for your great work. I transform the model from pytorch(.pth) to libtorch(.pt). When I load the model with libtorch in c++, and then get the error:

terminate called after throwing an instance of 'c10::Error' what(): [enforce fail at inline_container.cc:185] . file not found: retinaface_mobilenet/model.json frame #0: c10::ThrowEnforceNotMet(char const, int, char const, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, void const*) + 0x76 (0x7f0fb64d4e06 in /home/xsc/libs/libtorch/lib/libc10.so) frame #1: caffe2::serialize::PyTorchStreamReader::getFileID(std::cxx11::basic_string<char, std::char_traits, std::allocator > const&) + 0x4ac (0x7f0f705aa34c in /home/xsc/libs/libtorch/lib/libtorch.so) frame #2: caffe2::serialize::PyTorchStreamReader::getRecord(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) + 0x33 (0x7f0f705aa533 in /home/xsc/libs/libtorch/lib/libtorch.so)

I transform the model with python code : example = torch.rand(1, 3, width, height).cuda() trace_script_module = torch.jit.trace(net, example,check_trace=True) trace_script_module.save("/home/.../retinaface_mobilenet.pt")

And I load the model with c++: std::string modelpath = "/home/.../retinaface_mobilenet.pt"; torch::jit::script::Module module = torch::jit::load(modelpath)

How can I deal with the problem "The file not found: retinaface_mobilenet/model.json" ?

121649982 commented 4 years ago

have you solved the problem?

xiaofof commented 3 years ago

I also meet the same error , in my case, my pytorch version is 1.4.0 whitch is used to trace torchscript model , while my libtorch c++ backend version is 1.2.0, then I use pytorch 1.2.0 to trace again and error free.

wolfworld6 commented 3 years ago

check_trace=T hi,have you solved this error?