1. FCOS

1.1. 功能介绍

FCOS目标检测算法示例使用图片作为输入,利用BPU进行算法推理,发布包含目标类别和检测框的智能msg。

FCOS是地平线开源的Onnx模型,使用COCO数据集进行训练,支持的目标检测类型包括人、动物、水果、交通工具等共80种类型。

代码仓库:https://c-gitlab.horizon.ai/HHP/box/hobot_dnn

应用场景:FCOS发布于2019年,是一款单阶段的目标检测算法,可实现行人检测、车辆检测等功能,主要应用于自动驾驶、智能家居等领域。

多光谱的目标检测案例:https://github.com/hdjsjyl/Multispectral-FCOS

1.2. 支持平台

平台 运行方式 示例功能
旭日X3派 Ubuntu 20.04 · 启动MIPI/USB摄像头,并通过web展示推理渲染结果
· 使用本地回灌,渲染结果保存在本地
X86 Ubuntu 20.04 · 使用本地回灌,渲染结果保存在本地

1.3. 准备工作

旭日X3派

  1. 旭日X3派已烧录好地平线提供的Ubuntu 20.04系统镜像。

  2. 旭日X3派已成功安装TogetheROS.Bot。

  3. 旭日X3派已安装MIPI或者USB摄像头,无摄像头的情况下通过回灌本地JPEG/PNG格式图片或者MP4、H.264和H.265的视频方式体验算法效果。

  4. 确认PC机能够通过网络访问旭日X3派。

X86平台

  1. X86环境已配置好Ubuntu 20.04系统镜像。

  2. X86环境系统已成功安装tros.b。

1.4. 使用介绍

旭日X3派

使用MIPI摄像头发布图片

FCOS目标检测算法示例订阅sensor package发布的图片,经过推理后发布算法msg,通过websocket package实现在PC端浏览器上渲染显示发布的图片和对应的算法结果。

# 配置tros.b环境
source /opt/tros/setup.bash

# 配置MIPI摄像头
export CAM_TYPE=mipi

# 启动launch文件
ros2 launch dnn_node_example hobot_dnn_node_example.launch.py config_file:=config/fcosworkconfig.json image_width:=480 image_height:=272

使用USB摄像头发布图片

# 配置tros.b环境
source /opt/tros/setup.bash

# 配置USB摄像头
export CAM_TYPE=usb

# 启动launch文件
ros2 launch dnn_node_example hobot_dnn_node_example.launch.py config_file:=config/fcosworkconfig.json image_width:=480 image_height:=272

使用本地图片回灌

FCOS目标检测算法示例使用本地JPEG/PNG格式图片回灌,经过推理后将算法结果渲染后的图片存储在运行路径下。

# 配置tros.b环境
source /opt/tros/setup.bash

# 启动launch文件
ros2 launch dnn_node_example hobot_dnn_node_example_feedback.launch.py config_file:=config/fcosworkconfig.json image:=config/target.jpg

X86平台

使用本地图片回灌

FCOS目标检测算法示例使用本地JPEG/PNG格式图片回灌,经过推理后将算法结果渲染后的图片存储在本地的运行路径下。

# 配置tros.b环境
source /opt/tros/setup.bash

# 启动launch文件
ros2 launch dnn_node_example hobot_dnn_node_example_feedback.launch.py config_file:=config/fcosworkconfig.json image:=config/target.jpg

1.5. 结果分析

使用摄像头发布图片

在运行终端输出如下信息:

[example-3] [WARN] [1655092908.847609539] [example]: Create ai msg publisher with topic_name: hobot_dnn_detection
[example-3] [WARN] [1655092908.849393011] [example]: Create img hbmem_subscription with topic_name: /hbmem_img
[example-3] [WARN] [1655092543.834432739] [img_sub]: Sub img fps 31.16
[example-3] [WARN] [1655092543.864126080] [example]: Smart fps 31.56
[example-3] [WARN] [1655092544.867603759] [img_sub]: Sub img fps 30.01
[example-3] [WARN] [1655092544.899715339] [example]: Smart fps 29.95
[example-3] [WARN] [1655092545.900991853] [img_sub]: Sub img fps 30.01
[example-3] [WARN] [1655092545.931518037] [example]: Smart fps 30.07
[example-3] [WARN] [1655092546.901658559] [img_sub]: Sub img fps 30.00
[example-3] [WARN] [1655092546.938970895] [example]: Smart fps 29.79
[example-3] [WARN] [1655092547.934894494] [img_sub]: Sub img fps 30.01
[example-3] [WARN] [1655092547.973566486] [example]: Smart fps 29.98
[example-3] [WARN] [1655092548.967549745] [img_sub]: Sub img fps 30.10
[example-3] [WARN] [1655092548.997125216] [example]: Smart fps 30.30

输出log显示,发布算法推理结果的topic为hobot_dnn_detection,订阅图片的topic为/hbmem_img,订阅到的图片和算法推理输出帧率约为30fps。

在PC端的浏览器输入http://IP:8000 即可查看图像和算法渲染效果(IP为旭日X3派的IP地址):

../../../_images/render_web1.jpeg

使用本地图片回灌

在运行终端输出如下信息:

[example-1] [INFO] [1654766336.839353395] [PostProcessBase]: out box size: 6
[example-1] [INFO] [1654766336.839427767] [PostProcessBase]: det rect: 87.2364 259.123 409.917 371.59, det type: couch, score:0.782941
[example-1] [INFO] [1654766336.839523764] [PostProcessBase]: det rect: 374.212 175.732 510.993 375.211, det type: potted plant, score:0.719925
[example-1] [INFO] [1654766336.839597637] [PostProcessBase]: det rect: 167.183 335.857 234.13 355.308, det type: book, score:0.548071
[example-1] [INFO] [1654766336.839671426] [PostProcessBase]: det rect: 139.87 313.279 183.4 352.292, det type: potted plant, score:0.542984
[example-1] [INFO] [1654766336.839738966] [PostProcessBase]: det rect: 57.9695 148.59 83.5923 186.552, det type: potted plant, score:0.502935
[example-1] [INFO] [1654766336.839823755] [PostProcessBase]: det rect: 165.691 339.25 237.475 366.896, det type: book, score:0.500648

输出log显示,算法使用输入的图片推理出6个目标,并输出了目标检测框坐标(输出的坐标顺序分别是人体框的左上的x和y坐标,和右下的x和y坐标)和类别。存储的渲染图片文件名为render_feedback_0_0.jpeg,渲染图片效果:

../../../_images/render_feedback1.jpeg