Vision: Undefined reference to PSROIAlign_forward_cpu

Created on 17 Mar 2020  路  9Comments  路  Source: pytorch/vision

Hi! I want to achieve Inference of the script mask rcnn model on C++.
Following the instructions "Make maskrcnn scriptable" I've install TorchVision and Torch from source.
In Cmake of my application:
find_package(TorchVision REQUIRED)
find_package(Torch REQUIRED)
In cpp:

include

include

include

include

After that I make my example_appp, but got some error:
"In function PSROIAlign_forward(at::Tensor const&, at::Tensor const&, float, int, int, int)': /usr/local/include/torchvision/PSROIAlign.h:32: undefined reference to PSROIAlign_forward_cpu(at::Tensor const&, at::Tensor const&, float, int, int, int)'
CMakeFiles/example-app.dir/example-app.cpp.o: In function PSROIAlign_backward(at::Tensor const&, at::Tensor const&, at::Tensor const&, float, int, int, int, int, int, int, int)': /usr/local/include/torchvision/PSROIAlign.h:76: undefined reference to PSROIAlign_backward_cpu(at::Tensor const&, at::Tensor const&, at::Tensor const&, float, int, int, int, int, int, int, int)'"

What the main reason of the error could be?

help wanted c++ frontend

All 9 comments

@bmanga do you know what the problem might be?

Hi @two-names, did you also do the following in your CMakeListst.txt?

target_link_libraries(yourtarget PUBLIC TorchVision::TorchVision)

Hi @bmanga !
project(custom_ops) set(OpenCV_DIR /opencv-3.4.5/build/install/share/OpenCV/) find_package(OpenCV REQUIRED) set(Torch_DIR /torch_install_dir/share/cmake/Torch/) find_package(Torch REQUIRED) set(TorchVision_DIR /vision_install_dir/share/cmake/TorchVision/) find_package(TorchVision REQUIRED) find_package(Python3 COMPONENTS Development) add_executable(example-app example-app.cpp) target_link_libraries(example-app "${TORCH_LIBRARIES}" Python3::Python) set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

I installed 'torch' and 'vision' from repository with DCMAKE_INSTALL_PREFIX:
/vision_install_dir
/torch_install_dir

You don't seem to be linking against TorchVision. Can you try changing

target_link_libraries(example-app "${TORCH_LIBRARIES}" Python3::Python)

to

target_link_libraries(example-app PRIVATE "${TORCH_LIBRARIES}" TorchVision::TorchVision Python3::Python)

And see if that fixes the problem?

It works!!!
@bmanga , thank you for your help!!!

@two-names no problem :)
Can you close the issue given that it's fixed?

Thanks a lot @bmanga for the help!

What about adding some more documentation on how to build / link projects using torchvision from C++? Or maybe a small tutorial / example?

@fmassa no worries, I'm happy to help :)
The linking part is covered in the README, but I'm sure a tutorial/self-contained example would help a lot. I can dedicate some time to it this weekend.
Do you have any preferences / ideas on the format?

I think a self-contained example would be a great starting point, we can think about tutorials afterwards.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ppwwyyxx picture ppwwyyxx  路  33Comments

timonbimon picture timonbimon  路  28Comments

zsef123 picture zsef123  路  23Comments

mcleonard picture mcleonard  路  26Comments

varunagrawal picture varunagrawal  路  45Comments