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::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > 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<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)'
CMakeFiles/detect_node.dir/src/detect_node.cpp.o: In function `void ros::Publisher::publish<yolo4::box_<std::allocator<void> > >(yolo4::box_<std::allocator<void> > 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的下载链接不是有两种嘛,如下:

一种是 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

  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地球被支点撬走啦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值