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

边栏推荐
- Kubesphere - build MySQL master-slave replication structure
- BeanDefinitionRegistryPostProcessor
- Kubernetes notes (I) kubernetes cluster architecture
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- 代码管理工具
- [set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
- Svn branch management
- Time format record
- Use abp Zero builds a third-party login module (I): Principles
- Migrate data from Amazon aurora to tidb
猜你喜欢

Kubesphere - set up redis cluster

Kubernetes notes (VII) kuberetes scheduling

Oauth2.0 - using JWT to replace token and JWT content enhancement

Kubernetes notes (VI) kubernetes storage

Es remote cluster configuration and cross cluster search

【系统设计】邻近服务

YOLOV1学习笔记

Kubernetes notes (VIII) kubernetes security

In depth analysis of kubernetes controller runtime

Bio, NiO, AIO details
随机推荐
Disruptor learning notes: basic use, core concepts and principles
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Bio, NiO, AIO details
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
Kubernetes notes (VIII) kubernetes security
认识弹性盒子flex
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
tabbar的设置
Common interview questions
Characteristics and isolation level of database
Kubesphere - build MySQL master-slave replication structure
Mysql database
Project summary --04
Kubesphere - Multi tenant management
JMeter linked database
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Introduction to software engineering
Cesium 点击获三维坐标(经纬度高程)
Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading