当前位置:网站首页>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

边栏推荐
- Detailed explanation of findloadedclass
- [set theory] equivalence relation (concept of equivalence relation | examples of equivalence relation | equivalence relation and closure)
- 技术管理进阶——你了解成长的全貌吗?
- JMeter performance automation test
- Method of converting GPS coordinates to Baidu map coordinates
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Cesium entity (entities) entity deletion method
- Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
- 【系统设计】邻近服务
- BeanDefinitionRegistryPostProcessor
猜你喜欢

Core principles and source code analysis of disruptor

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)

深入解析kubernetes controller-runtime

Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency

.NET程序配置文件操作(ini,cfg,config)

2022 CISP-PTE(三)命令执行

Kubernetes notes (VI) kubernetes storage

Une exploration intéressante de l'interaction souris - pointeur

Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样

YOLOV2学习与总结
随机推荐
智牛股项目--04
Jedis source code analysis (I): jedis introduction, jedis module source code analysis
Tabbar settings
Kubesphere - set up redis cluster
智牛股项目--05
Pdf files can only print out the first page
Naive Bayes in machine learning
Creating postgre enterprise database by ArcGIS
MySQL帶二進制的庫錶導出導入
Install VM tools
Print time Hahahahahaha
Synthetic keyword and NBAC mechanism
. Net program configuration file operation (INI, CFG, config)
项目总结--01(接口的增删改查;多线程的使用)
Oauth2.0 - user defined mode authorization - SMS verification code login
Luogu problem list: [mathematics 1] basic mathematics problems
Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
Detailed explanation of findloadedclass
CKA certification notes - CKA certification experience post
Request weather interface format, automation