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

边栏推荐
- PMP笔记记录
- Oauth2.0 - explanation of simplified mode, password mode and client mode
- 表达式的动态解析和计算,Flee用起来真香
- Creating postgre enterprise database by ArcGIS
- Get a screenshot of a uiscrollview, including off screen parts
- Jedis source code analysis (II): jediscluster module source code analysis
- 代码管理工具
- Some thoughts on machine learning
- Page text acquisition
- Bio, NiO, AIO details
猜你喜欢

Push box games C #

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

Multithreading and high concurrency (7) -- from reentrantlock to AQS source code (20000 words, one understanding AQS)

How to scan when Canon c3120l is a network shared printer

Es remote cluster configuration and cross cluster search

SVN分支管理

YOLOV3学习笔记

有意思的鼠标指针交互探究

Redis cluster creation, capacity expansion and capacity reduction

Kubernetes notes (I) kubernetes cluster architecture
随机推荐
Migrate data from Mysql to tidb from a small amount of data
YOLOV2学习与总结
PMP笔记记录
Zhiniu stock project -- 04
Install VM tools
Detailed explanation of findloadedclass
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
What's the difference between using the Service Worker Cache API and regular browser cache?
Use abp Zero builds a third-party login module (I): Principles
Nacos service installation
Oracle Database Introduction
Mysql database
从小数据量 MySQL 迁移数据到 TiDB
Redis cluster creation, capacity expansion and capacity reduction
Une exploration intéressante de l'interaction souris - pointeur
【无标题】8 简易版通讯录
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
Kubernetes notes (IV) kubernetes network
23 design models
Bio, NiO, AIO details