文章说明:关于openvino环境版本,需要安装OpenVINO 2020版本,笔者实测,在OpenVINO 2020.3.194、2020.3.341、2020.3.355环境下都可以运行ros_openvino_toolkit项目。
先决条件
- 支持的CPU型号:x86_64,包括:
- 6th-8th Generation Intel® Core™
- Intel® Xeon® v5 family
- Intel® Xeon® v6 family
- 支持的集成显卡配置(可选)
- 6th to 8th generation Intel® Core™ processors with Iris® Pro graphics and Intel® HD Graphics
- 6th to 8th generation Intel® Xeon® processors with Iris Pro graphics and Intel HD Graphics (excluding the e5 product family, which does not have graphics)
- Intel® Pentium® processors N4200/5, N3350/5, N3450/5 with Intel HD Graphics
- 操作系统:Ubuntu 18.04 LTS
- ROS Melodic
- OpenVINO 2020.3 LTS
- RGB 摄像头(RealSense D400 系列或标准USB 摄像头)或 视频/图像文件作为输入
一、配置环境
这里仅以无sudo权限安装2020.3.194版本作为参考,仅仅只是提供一种思路。请读者根据实际项目需求,自行选择安装版本和方式。
1. 安装Open VINO 2020.3.194环境
参考
a. 在Ubuntu系统上无sudo权限命令行安装OpenVINO
环境信息如下:
- Ubuntu18.04
- OpenVINO™ Version 2020.3
这里的安装方式是下载安装包并安装。下载解压步骤内容不再赘述,官方教程里面讲解很详细。
接下来进入OpenVINO解压后的目录,这里以~/Downloads
目录为例:
cd ~/Downloads/l_openvino_toolkit_p_2020.3.194/
sh ./install.sh
执行无UI安装脚本后,按照提示安装(这里我是通过默认安装,安装目录在~/intel/openvino
)
接下来source
./bin
文件夹下的setupvars.sh
,并将以下命令添加到.bashrc
文件中(如果默认终端是zsh,就添加到.zshrc
文件)
source ~/intel/openvino/bin/setupvars.sh
b. 验证安装成功
进入demo文件夹,执行验证脚本
cd ~/intel/openvino/deployment_tools/demo
# 将样例和模型全下载下来,并编译
./demo_squeezenet_download_convert_run.sh
# 编译通过后执行
~/inference_engine_samples_build/intel64/Release/classification_sample_async -i car.png -m ~/openvino_models/ir/public/squeezenet1.1/FP16/squeezenet1.1.xml -d CPU
编译成功截图:
c. 安装MO
参考Configuring the Model Optimizer(2020.3版本)
- 进入安装目录
cd ~/intel/openvino/deployment_tools/model_optimizer
- 使用OpenVINO提供的虚拟环境安装MO
这里最好还是用虚拟环境,毕竟没有root权限,无法在系统的/etc/python3/目录下安装。
使用anaconda的python可以安装,也可以使用它提供的额外的虚拟环境。
- 新建虚拟环境
virtualenv --system-site-packages -p python3 ./venv
- 启动虚拟环境
source ./venv/bin/activate
- 安装MO
cd ./install_prerequisites/ && ./install_prerequisites.sh
- 设置环境变量
将alias venv_activate='source ~/intel/openvino/deployment_tools/model_optimizer/venv/bin/activate'
添加到.zshrc
或者.bashrc
中,需要激活虚拟环境时,运行venv_activate
即可
2. 安装ROS环境
a. 换源
# 备份原来的sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
# 修改sources.list
sudo gedit /etc/apt/sources.list
将sources.list
替换成以下内容:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
b. 添加ros-latest.list并更新
参考ROS wiki官方教程安装时,有可能会出现如图所示的错误,这时可以尝试以下解决办法:
sudo sh -c 'echo "deb https://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ bionic main
" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
sudo apt update
参考链接:
- Ubuntu 镜像使用帮助- 清华大学开源软件镜像站: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
- ROS Wiki:Ubuntu install of ROS Melodic: http://wiki.ros.org/melodic/Installation/Ubuntu
- ROS 镜像使用帮助-清华大学开源软件镜像站: https://mirrors.tuna.tsinghua.edu.cn/help/ros/
c. 激活ros环境
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
d. 安装ROS编译相关的包
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
按照官网教程,运行以下命令:
sudo rosdep init
sudo rosdep fix-permissions
rosdep update
这时候报错:cannot download default sources list
解决办法:
进入网站 https://ip.tool.chinaz.com/raw.githubusercontent.com,我们可以看到
raw.githubusercontent.com
的IPV4地址,将其添加到/etc/hosts
中,如185.199.109.133 raw.githubusercontent.com
并尝试运行
sudo rosdep init
如果运行rosdep init
命令且终端显示超时报错时,可以尝试以下办法:sudo gedit /etc/resolv.conf
在文件末尾添加以下内容:
nameserver 8.8.8.8 #google域名服务器 nameserver 8.8.4.4 #google域名服务器
PS: 为了加速GitHub访问,推荐将以下内容添加到 /etc/hosts
文件中。
参考链接: https://gitee.com/ineo6/hosts
# GitHub Host Start
185.199.108.154 github.githubassets.com
140.82.112.22 central.github.com
185.199.108.133 desktop.githubusercontent.com
185.199.108.153 assets-cdn.github.com
185.199.108.133 camo.githubusercontent.com
185.199.108.133 github.map.fastly.net
199.232.5.194 github.global.ssl.fastly.net
140.82.112.4 gist.github.com
185.199.108.153 github.io
140.82.113.3 github.com
140.82.114.5 api.github.com
185.199.108.133 raw.githubusercontent.com
185.199.108.133 user-images.githubusercontent.com
185.199.108.133 favicons.githubusercontent.com
185.199.108.133 avatars5.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.108.133 avatars3.githubusercontent.com
185.199.108.133 avatars2.githubusercontent.com
185.199.108.133 avatars1.githubusercontent.com
185.199.108.133 avatars0.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
140.82.113.9 codeload.github.com
52.217.94.28 github-cloud.s3.amazonaws.com
52.217.107.84 github-com.s3.amazonaws.com
52.217.104.4 github-production-release-asset-2e65be.s3.amazonaws.com
52.216.88.43 github-production-user-asset-6210df.s3.amazonaws.com
52.216.141.188 github-production-repository-file-5c1aeb.s3.amazonaws.com
185.199.108.153 githubstatus.com
64.71.144.202 github.community
185.199.108.133 media.githubusercontent.com
# Please Star : https://github.com/ineo6/hosts
# Mirror Repo : https://gitee.com/ineo6/hosts
# Update at: 2021-08-15 22:08:52
# GitHub Host End
3. 安装配置realsense相关环境
sudo apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo bionic main" -u
sudo apt update
sudo apt-get install librealsense2-dev
sudo apt-get install ros-melodic-librealsense2
4. 安装gflags-dev库
sudo apt-get install -y libgflags-dev
5. 设置环境变量
将以下内容添加到.bashrc
或者.zshrc
里面
export CPU_EXTENSION_LIB+=~/intel/openvino/deployment_tools/inference_engine/lib/intel64/libinference_engine.so
export GFLAGS_LIB+=/usr/lib/x86_64-linux-gnu/libgflags_nothreads.a
三、编译ros_openvino_toolkit
1. 下载
获取代码
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
在工作空间下的src目录中,下载ros_openvino_toolkit dev-ov2020.3:
git clone https://github.com/intel/ros_openvino_toolkit.git
cd ros_openvino_toolkit/
git checkout dev-ov2020.3
如果网络状况不佳,下载缓慢,可以尝试使用gitee:
git clone https://gitee.com/openvinotoolkit-robotics/ros_openvino_toolkit.git
cd ros_openvino_toolkit/
git checkout dev-ov2020.3
2. 编译
在工作空间根目录下编译:
cd ~/catkin_ws
catkin_make_isolated
source ./devel_isolated/setup.bash
3. 关于配置文件说明
修改 vino_launch/param
文件夹下的yaml文件(以pipeline_object.yaml为例):
inputs
有几种选项:StandardCamera
,RealSenseCamera
,Image
,Video
model
指向OpenVINO IR模型中xml文件的绝对路径- engine有好几种选项
CPU
,GPU
,MYRIAD
, 我们这里使用CPU做验证。
四. 下载模型
模型分为intel和public,我们先以intel的一个模型来做例子
关于下载模型时可能遇到的问题:
OpenVINO中文社区针对国内开发者下载缓慢的痛点,专门将常用public模型放入gitee仓库https://gitee.com/openvinotoolkit-prc/public_models.git中,欢迎大家共同维护!
git clone https://gitee.com/openvinotoolkit-prc/public_models.git
使用MO转换模型
1. 更新protobuf
如果在运行mo时报错:
[ ERROR ]
Detected not satisfied dependencies:
protobuf: not installed, required: 3.6.1
根据提示,需要安装protobuf,版本3.6.1
解决办法:更新protobuf
- protobuf下载列表: https://github.com/protocolbuffers/protobuf/releases
- 解压安装
tar -xf protobuf-all-3.6.1.tar.gz
cd protobuf-3.6.1
./configure
make
make check
sudo make install
cd ./python
python3 setup.py build
python3 setup.py test
sudo python3 setup.py install
2. 设置快捷键
添加以下命令到.zshrc
或者.bashrc
中:
alias model_printall='python3 ~/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --print_all'
alias model_grep='python3 ~/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --print_all | grep'
alias model_download_name='cd ~/intel/openvino/deployment_tools/open_model_zoo/tools/downloader && python3 ~/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name'
alias cd_model_dir='cd ~/intel/openvino/deployment_tools/open_model_zoo/tools/downloader'
model_printall
: 打印输出所有OpenVINO支持的model名称model_grep
: 在model_printall
的基础之上使用grep命令model_download_name
: 使用OpenVINO模型下载器,对特定名称的model进行下载cd_model_dir
: 进入下载好的模型路径下。
3. 模型转换
sudo python3 /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/converter.py --name=mobilenet-ssd --mo /opt/intel/openvino/deployment_tools/model_optimizer/mo.py
给模型下载路径设置链接
sudo mkdir -p /opt/ros_openvino_toolkit
sudo ln -s /home/cxs/intel/openvino/deployment_tools/open_model_zoo/tools/downloader /opt/ros_openvino_toolkit/models