一、基础知识
(一)Vitis™ AI开发环境
Vitis™ AI开发环境可在赛灵思硬件平台上加速 AI 推断,包括边缘器件和 Alveo™ 加速器卡。此环境由经过最优化的 IP 核、工具、库、模型和设计示例组成。其设计以高效和易用为核心,旨在通过赛灵思 SoC 和自适应计算加速平台 (ACAP) 来充分发掘 AI 加速的全部潜能。Vitis AI 开发环境将底层可编程逻辑的繁复细节加以抽象化,从而帮助不具备 FPGA 知识的用户轻松开发深度学习推断应用。
(二)Vitis AI Model Zoo
Vitis AI 有个很有重要的工具:Vitis AI Model Zoo,类似于Vitis AI的模型商城。
Vitis AI Model Zoo 包含经过最优化的深度学习模型,可在赛灵思平台上加速部署深度学习推断。这些模型涵盖了不同的应用,包括 ADAS/AD、视频监控机器人学和数据中心等。用户可从这些经过预训练的模型开始着手,享受深度学习加速所带来的诸多利益。
(三)ADAS
高级驾驶辅助系统(Advanced Driving Assistance System)是利用安装在车上的各式各样传感器(毫米波雷达、激光雷达、单双目摄像头以及卫星导航),在汽车行驶过程中随时来感应周围的环境,收集数据,进行静态、动态物体的辨识、侦测与追踪,并结合导航地图数据,进行系统的运算与分析,从而预先让驾驶者察觉到可能发生的危险,有效增加汽车驾驶的舒适性和安全性。 近年来ADAS市场增长迅速,原来这类系统局限于高端市场,而现在正在进入中端市场,与此同时,许多低技术应用在入门级乘用车领域更加常见,经过改进的新型传感器技术也在为系统布署创造新的机会与策略。
二、环境搭建
Vitis AI 库有两种安装方法。一种是通过配置 PetaLinux 来重构系统,另一种则是在线安装 Vitis AI 库,安装 Vitis-AI 库后,再安装 Vitis-AI 从属库。
(一)系统下载&安装
PetaLinux 以前没玩过,那就体验一把。先从官网下载PetaLinux系统镜像(https://china.xilinx.com/member/forms/download/design-license-xef.html?filename=xilinx-kv260-dpu-v2022.2-v3.0.0.img.gz),注意先注册AMD账号,然后填写一些信息才能注册成功,压缩文件有3.3G,解压后的文件8.8G。
注意文件命名,Vitis AI 版本为V3.0.0,此处有个坑,后续遇到再说。IMG文件烧录TF卡后上电,PetaLinux 就这样:
root@xilinx-kv260-starterkit-20222:~/Vitis-AI# uname -a
Linux xilinx-kv260-starterkit-20222 5.15.36-xilinx-v2022.2 #1 SMP Mon Oct 3 07:50:07 UTC 2022 aarch64 aarch64 aarch64 GNU/
root@xilinx-kv260-starterkit-20222:~/Vitis-AI#
映入眼帘的就是2个文件夹,包括鼎鼎大名的Vitis-AI :
接下来将在这个文件夹中玩的不亦乐乎。
(二)准备图像包
在官方链接(https://china.xilinx.com/bin/public/openDownload?filename=vitis_ai_runtime_r3.0.0_image_video.tar.gz)下载`vitis_ai_runtime_r3.0.0_image_video.tar.gz,其中包括demo需要的图像和视频文件,下载后解压备用。
三、ADAS目标识别
Vitis AI 提供L了许多实例,其中包括一个ADAS目标识别的demo,在Vitis-AI/examples/vai_runtime/adas_detection中,可执行CPP程序已经编译好,可以直接执行。
在执行demo之前,先看看readme。
Before running the program, please download the corresponding model and install it.
The model required by this sample is: yolov3_adas_pruned_0_9
You can find the detailed informantion of this model under
Vitis-AI/models/AI-Model-Zoo/model-list/dk_yolov3_cityscapes_256_512_0.9_5.46G_1.3/model.yaml
In the model.yaml, you will find the model's download links for different platforms.
Please choose the corresponding model and download it.
Take ZCU102/ZCU104 as an example, execute the following commands to download and install the model.
wget https://www.xilinx.com/bin/public/openDownload?filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r2.5.0.tar.gz -O yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r2.5.0.tar.gz
mkdir -p /usr/share/vitis_ai_library/models
tar -xzvf yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r2.5.0.tar.gz
cp yolov3_adas_pruned_0_9 /usr/share/vitis_ai_library/models -r
把非KV260的内容截掉了,readme基本上就是告诉用户,去Vitis AI Model Zoo下载相应的model并安装。
那就照着guideline开动,将之前图形包中的adas.webm文件拷贝至当前目录,然后执行
./adas_detection adas.webm /usr/share/vitis_ai_library/models/yolov3_adas_pruned_0_9/yolov3_adas_pruned_0_9.xmodel
嗯,出错了:
**注意,坑来了!**系统提示
Please re-compile xmodel
是不是?要不去重编xmodel?仔细看看问题,原来是系统是Vitis AI V3.0,xmodel却是V2.5,导致CHECK fingerprint fail,直接去Vitis AI Model Zoo下载个V3.0的xmodel就好了,说干就干!
root@xilinx-kv260-starterkit-20222:~/Vitis-AI/examples/vai_runtime/adas_detection# wget https://www.xilinx.com/bin/public/openDownload?filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz -O yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz
--2023-09-27 06:52:41-- https://www.xilinx.com/bin/public/openDownload?filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz
Resolving www.xilinx.com... 223.119.248.58, 223.119.248.90
Connecting to www.xilinx.com|223.119.248.58|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://xilinx-ax-dl.entitlenow.com/dl/ul/2023/01/06/R210771244/yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz?hash=PJrrJ06TWqMoH_m1gKVgXw&expires=1695855161&filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz [following]
--2023-09-27 06:52:41-- https://xilinx-ax-dl.entitlenow.com/dl/ul/2023/01/06/R210771244/yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz?hash=PJrrJ06TWqMoH_m1gKVgXw&expires=1695855161&filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz
Resolving xilinx-ax-dl.entitlenow.com... 223.119.244.25
Connecting to xilinx-ax-dl.entitlenow.com|223.119.244.25|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://amd-ax-dlf.entitlenow.com/dl/ul/2023/01/06/R210771244/yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz?hash=PJrrJ06TWqMoH_m1gKVgXw&expires=1695855161&filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz [following]
--2023-09-27 06:52:45-- https://amd-ax-dlf.entitlenow.com/dl/ul/2023/01/06/R210771244/yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz?hash=PJrrJ06TWqMoH_m1gKVgXw&expires=1695855161&filename=yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz
Resolving amd-ax-dlf.entitlenow.com... 223.119.248.34, 223.119.248.40, 2402:4f00:4002:400::df77:f828, ...
Connecting to amd-ax-dlf.entitlenow.com|223.119.248.34|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1875420 (1.8M) [application/octet-stream]
Saving to: 'yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz'
yolov3_adas_pruned_0_9-zcu102_ 100%[==================================================>] 1.79M 1.54MB/s in 1.2s
2023-09-27 06:52:50 (1.54 MB/s) - 'yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz' saved [1875420/1875420]
root@xilinx-kv260-starterkit-20222:~/Vitis-AI/examples/vai_runtime/adas_detection#
再次执行以下命令:
root@xilinx-kv260-starterkit-20222:~/Vitis-AI/examples/vai_runtime/adas_detection# tar -xzvf yolov3_adas_pruned_0_9-zcu102_zcu104_kv260-r3.0.0.tar.gz
yolov3_adas_pruned_0_9/
yolov3_adas_pruned_0_9/meta.json
yolov3_adas_pruned_0_9/yolov3_adas_pruned_0_9.xmodel
yolov3_adas_pruned_0_9/md5sum.txt
yolov3_adas_pruned_0_9/yolov3_adas_pruned_0_9.prototxt
yolov3_adas_pruned_0_9_acc/
yolov3_adas_pruned_0_9_acc/yolov3_adas_pruned_0_9_acc.prototxt
yolov3_adas_pruned_0_9_acc/yolov3_adas_pruned_0_9_acc.xmodel
root@xilinx-kv260-starterkit-20222:~/Vitis-AI/examples/vai_runtime/adas_detection# cp yolov3_adas_pruned_0_9 /usr/share/vitis_ai_library/models -r
四、ADAS目标识别体验
(一)目标识别
接上HDMI显示器、键盘&鼠标,在KV260上执行(如果在SSH或串口上执行会提示cv::Exception):
`./adas_detection video/adas.webm /usr/share/vitis_ai_library/models/yolov3_adas_pruned_0_9/yolov3_adas_pruned_0_9.xmodel`
视频在最后,可以看出识别的准确性和实时性都不错,FPS保持在40左右。
(二)dashboard监测
KV260在PetaLinux上提供了一个Hardware Platform Statistics页面,挺有意思的,用于展示系统硬件资源实时消耗情况。监控的内容包括CPU消耗、内存空闲和消耗、电压、温度…
下面是一张执行ADAS目标识别后CPU使用情况,可以看出CPU使用率一下子拉升了,A53的资源还是紧张了点,要是A72就好了。