当前位置:网站首页>ROS+Pytorch的联合使用示例(语义分割)
ROS+Pytorch的联合使用示例(语义分割)
2022-07-03 06:18:00 【昼行plus】
本篇根据 ROS图像的Deeplab v3+实时语义分割(ROS+Pytorch)进行踩坑记录,并附加一些对应操作的理解。(自觉有很多理解不到位的地方,若有大佬路过还请不吝赐教!)
首先,上面那篇文章写的非常好!代码也很nice,本文对其代码进行了稍微改动了一下,gitee地址
本代码主要针对ubuntu 18.04,ros-melodic版本;
ubuntu20.04的ros-noetic因为自带python3,有可能没这么麻烦。
其实在编译时需要做下面这些指定,意思是用anaconda的python编译代码,而catkin又默认有ros的路径,这样就可以同时调用anaconda环境和ros的各种库了!
catkin config -DPYTHON_EXECUTABLE=/home/daybeha/anaconda3/bin/python -DPYTHON_INCLUDE_DIR=/home/daybeha/anaconda3/include/python3.9 -DPYTHON_LIBRARY=/home/daybeha/anaconda3/lib/libpython3.9.so -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF

这里需要注意的是,一定要自己去对应路径看看有没有相关文件,相关文件到底怎么命名的,比如原问写的是libpython3.6m.so,但我的路径下只有libpython3.9.so,那么m也不能要(虽然不知道这个’m’代表什么……)
虽然已经可以调用ros和anaconda的库了,但是ros接收信息常会遇到图像信息的转换,这需要用到cv_bridge。
因为在Ubuntu18.04下,ros的python是2.7版本,系统中的cv_bridge是用python2编译的。但若想使用pytorch,就需要在python3下进行编译,这个时候代码中的cv_bridge就会报类似如下错误:
因此需要用到python3编译的cvbuguobuguo_bridge版本,它在代码里的vision_opencv文件夹,其原始github地址为https://github.com/ros-perception/vision_opencv
这里一定注意catkin build后的路径不能写错!!!
若写错的话,系统找不到就还会去环境变量的路径里去找,然而那个路径里只有python2.7,不能编译这个版本的cv_bridge
从而报错
不过要调用代码包里的cv_bridge,这样还是不够的,在import cv_bridge之前,为避免调用到ros用python2.7编译的cv_bridge,需要首先制定库的路径,即predict.py的第7行(这部分我有改动,请参考本文提供的代码):
博文说可以不用上面第七行而是在catkin build编译之后的source后加 --extend,即
source devel/setup.bash --extend
roslaunch img_seg run.launch
不过我自己试了一下,不管是上面第7行的代码,还是–extend ,加不加都不影响…… 大家可以自己试一试。
另外跑通代码的话还需要修改这两项,分别是图像话题名称img_topic,和pth模型路径ckpt。
之后便可catkin build进行编译。
完成编译后,执行
source devel/setup.bash
roslaunch img_seg run.launch
然后rosbag play kitti的bag包即可看到如下效果。
关于kitti数据怎么转换为rosbag
当然你也可以用Euroc等自带rosbag的数据,对应更改图像话题即可。ROS图像的Deeplab v3+实时语义分割(ROS+Pytorch)

Reference
ROS图像的Deeplab v3+实时语义分割(ROS+Pytorch)
python3环境下使用cv_bridge
与标题无关
git如何不用每次pull和push输入用户名密码:
先输入
git config --global credential.helper store
然后再pull或者push一次输入用户名密码,以后就不用再输入啦!
git push origin master

边栏推荐
- Use @data in Lombok to simplify entity class code
- Interesting research on mouse pointer interaction
- YOLOV3学习笔记
- Selenium ide installation recording and local project maintenance
- ODL framework project construction trial -demo
- Kubesphere - Multi tenant management
- Bio, NiO, AIO details
- The win7 computer can't start. Turn the CPU fan and stop it
- Important knowledge points of redis
- Judge whether the date time exceeds 31 days
猜你喜欢

Cesium 点击获取模型表面经纬度高程坐标(三维坐标)

【系统设计】邻近服务

Creating postgre enterprise database by ArcGIS

Reinstalling the system displays "setup is applying system settings" stationary

JMeter linked database

phpstudy设置项目可以由局域网的其他电脑可以访问

Synthetic keyword and NBAC mechanism

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Zhiniu stock -- 03

Detailed explanation of contextclassloader
随机推荐
Migrate data from Amazon aurora to tidb
技术管理进阶——你了解成长的全貌吗?
Kubernetes notes (IX) kubernetes application encapsulation and expansion
Kubesphere - build MySQL master-slave replication structure
JMeter performance automation test
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Exportation et importation de tables de bibliothèque avec binaires MySQL
About the difference between count (1), count (*), and count (column name)
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Kubesphere - build Nacos cluster
Migrate data from Mysql to tidb from a small amount of data
JMeter linked database
项目总结--01(接口的增删改查;多线程的使用)
Characteristics and isolation level of database
Disruptor learning notes: basic use, core concepts and principles
Leetcode solution - 02 Add Two Numbers
Advanced technology management - do you know the whole picture of growth?
Leetcode solution - 01 Two Sum
Leetcode problem solving summary, constantly updating!
【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF