Closed mattpopovich closed 3 years ago
The solution for this is to make sure you are including the following:
#include <torch/script.h> // One-stop header; for torch::jit::load()
#include <torchvision/vision.h> // For torchvision NMS in model
If that doesn't work, I checked ldd
and it looked like the torchvision library was not actually being included.
Failing executable:
# ldd path/to/failing/executable | grep torch
libc10.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libc10.so (0x00007fe09b466000)
libtorch.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch.so (0x00007fe089dd3000)
libtorch_cpu.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch_cpu.so (0x00007fe07fe70000)
libtorch_cuda.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch_cuda.so (0x00007fe030163000)
libc10_cuda.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libc10_cuda.so (0x00007fe01fe6b000)
Working executable (note libtorchvision.so
):
# ldd /path/to/working/executable | grep torch
libc10.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libc10.so (0x00007f293c174000)
libtorchvision.so => /usr/local/lib/libtorchvision.so (0x00007f293bba4000)
libtorch.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch.so (0x00007f293bb9f000)
libtorch_cpu.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch_cpu.so (0x00007f2931c3c000)
libtorch_cuda.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libtorch_cuda.so (0x00007f28e1f52000)
libc10_cuda.so => /usr/local/lib/python3.8/dist-packages/torch/lib/libc10_cuda.so (0x00007f28e16d5000)
In order for libtorchvision.so
to be successfully included, I had to #include <torchvision/models/resnet.h>
and then actually use that in my code:
auto model = vision::models::ResNet18( );
That was the easiest way I found to actually use something from torchvision in your code... After that, the failing executable showed libtorchvision.so
with ldd
and I was able to successfully load my yolov5-rt-stack
model with NMS post-processing in C++! :partying_face:
Hi @mattpopovich , Thanks for the tip here, it was very useful. I had some similar ldd
linking problems when I was first compiling torchvision
.
🐛 Bug
When attempting to load the yolov5-rt-stack model (with NMS post-processing) in C++, the following error appears:
To Reproduce (REQUIRED)
Steps to reproduce the behavior:
Expected behavior
The model loads via
torch::jit::load()
without issue.Environment