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

边栏推荐
- 简易密码锁
- CKA certification notes - CKA certification experience post
- Oauth2.0 - user defined mode authorization - SMS verification code login
- Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
- In depth analysis of kubernetes controller runtime
- 从小数据量分库分表 MySQL 合并迁移数据到 TiDB
- Various usages of MySQL backup database to create table select and how many days are left
- Virtual memory technology sharing
- 深入解析kubernetes controller-runtime
- Detailed explanation of contextclassloader
猜你喜欢

Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster

Tabbar settings

Cesium 点击获三维坐标(经纬度高程)
![[system design] proximity service](/img/4a/2e68536cbe385af1d1a591e674fbf0.png)
[system design] proximity service

Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation

Project summary --2 (basic use of jsup)

SQL实现将多行记录合并成一行

YOLOV1学习笔记

Project summary --04

Important knowledge points of redis
随机推荐
.NET程序配置文件操作(ini,cfg,config)
Luogu problem list: [mathematics 1] basic mathematics problems
Shell conditional statement
Introduction to software engineering
Analysis of Clickhouse mergetree principle
Difference between shortest path and minimum spanning tree
Reinstalling the system displays "setup is applying system settings" stationary
Use @data in Lombok to simplify entity class code
表达式的动态解析和计算,Flee用起来真香
Simple handwritten ORM framework
Creating postgre enterprise database by ArcGIS
致即将毕业大学生的一封信
Cesium entity (entities) entity deletion method
剖析虚幻渲染体系(16)- 图形驱动的秘密
Detailed explanation of findloadedclass
Apifix installation
Oauth2.0 - use database to store client information and authorization code
Get a screenshot of a uiscrollview, including off screen parts
SVN分支管理
代码管理工具