YOLOv4在ROS-Melodic上的部署-libtorch(附源码,非Darknet)

有关YOLOv4-LibTorch的部署可以看我的这篇博客。

然后移植到ROS-Melodic上就相对简单了。

直接上GitHub链接吧。

初版可能有点乱,但是注释挺详细,欢迎交流经验哈~

2020.12.16 更新 YOLO4-libtorch GPU版本的ROS实现

CPU版:GitHub - wsx000/YOLOv4-LibTorch-CPU-ROS-deployment: this is a Deployment of YOLOv4 on ROS-Melodic with LibTorch

GPU版:https://github.com/wsx000/YOLO4-ROS-GPU

wawawawawaT_T眼泪都要出来了!!终于成功地把GPU版本的YOLO4-libtorch移植到了ROS-Melodic上了,一个bug卡了四五天了T_T,一直在崩溃的边缘疯狂试探,终于成了T_T。

改bug的心酸历程:

因为最近出了torch1.7.1版本的,所以我就想尝鲜一下,用最新版本的libtorch1.7.1-cuda10.2来实现yolo4的GPU加速。刚开始很顺利,中间出了一些小bug但都好解决,单纯ubuntu18环境下的部署很快就完成了,我已经上传到github上了,这次对代码的可读性做了一些优化,不想上一版那么乱了,,感兴趣的朋友可以查看YOLOv4-LibTorch-GPU。

但!!问题就在我往Melodic上移植上面,配置反反复复检查了无数遍,真心没啥问题了。。总是catkin_make无法通过,一直在报错如下:

CMakeFiles/detect_node.dir/src/detect_node.cpp.o: In function `main':
detect_node.cpp:(.text+0x118): undefined reference to `ros::init(int&, char**, std::string const&, unsigned int)'
detect_node.cpp:(.text+0x1aa): undefined reference to `ros::NodeHandle::NodeHandle(std::string const&, std::map, std::allocator > > const&)'
detect_node.cpp:(.text+0x28d): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
detect_node.cpp:(.text+0x372): undefined reference to `ros::console::print(ros::console::FilterBase*, void*, ros::console::levels::Level, std::basic_stringstream, std::allocator > const&, char const*, int, char const*)'
CMakeFiles/detect_node.dir/src/detect_node.cpp.o: In function `void ros::Publisher::publish > >(yolo4::box_ > const&) const':
detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0xb0): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0x1dc): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0x2fa): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0x440): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0x56c): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
CMakeFiles/detect_node.dir/src/detect_node.cpp.o:detect_node.cpp:(.text._ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_[_ZNK3ros9Publisher7publishIN5yolo44box_ISaIvEEEEEvRKT_]+0x6a1): more undefined references to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)' follow
collect2: error: ld returned 1 exit status
yolo4/CMakeFiles/detect_node.dir/build.make:196: recipe for target '/home/curious/code/ROS/yolo4-ros/devel/lib/yolo4/detect_node' failed
make[2]: *** [/home/curious/code/ROS/yolo4-ros/devel/lib/yolo4/detect_node] Error 1
CMakeFiles/Makefile2:1064: recipe for target 'yolo4/CMakeFiles/detect_node.dir/all' failed
make[1]: *** [yolo4/CMakeFiles/detect_node.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2

这个问题一般都是在cmakelists.txt中没有加入相应的链接库导致的,但是我明明加了!在网上找了解决方法,还有把ROS重装了三四遍依然没有解决问题!!想到之前用libtorch1.5.0就没遇到过这样的问题,所以考虑是不是libtorch出版本的问题,因此换了以下libtorch1.7.0,在极度绝望的心情中一点都不怀希望的试了试,结果!!竟然成功编译通过了啊啊!!果然是libtorch版本的问题!可能最新的1.7.1版本的libtorch库跟ROS的库一起链接的时候会不兼容吧,啊啊啊快一周了这个破问题真的令人伤心欲绝,曾经还一度想更换部署的框架。。。。

有关问题我还一度在在GitHub上问了下,有相似问题的小伙伴可以参考一下。

GitHub搬运工:

 

具体用什么方法自己看着办哈哈哈 

废话不多说了,直接上源代码链接吧:YOLO4-ROS-GPU。使用方法晚些我会更新在Github中。目前实测帧率大概21FPS左右,因为还没对代码进行性能优化,所以后续还有很大的提升空间。

另外补充一点—libtorch中 Pre-cxx11 ABI 与 cxx11 ABI 的区别:

记录一下一些小的知识点:libtorch的下载链接不是有两种嘛,如下:

YOLOv4在ROS-Melodic上的部署-libtorch(附源码,非Darknet)_第1张图片

一种是 Pre-cxx11 ABI  另外一种是  cxx11 ABI  ,在使用过程中从没见过有人说过这俩的区别,只是简单地贴了俩链接上来也没说要用哪个。。。最近改bug的同时也学到了不少小知识。这里的Pre-cxx11 ABI其实就是C++11之前的ABI,cxx11 ABI 是C++11的ABI,因为现在基本都用C++11之后的版本了,所以一般情况下是下载cxx11 ABI版本的使用的。即下载下来后因该是类似这样的命名:

libtorch-cxx11-abi-shared-with-deps-version.zip

其实两种版本的区别很小,我目前找到的唯一的区别就是两者在其文件share/cmake/Torch/TorchConfig.cmake文件中第122行那一句话的设置上,这点区别很明显,如下:

Pre-cxx11 ABI

cxx11 ABI

你可能感兴趣的:(ROS,LibTorch/模型部署,pytorch,c++)