基于 MCU 的多人检测器
在基于 MCU 的系统上使用卷积神经网络 (CNN) 开发和部署人体检测器的分步指南;
概述
以下是 mlpersondetector 文件夹中可用的所有组件的列表。
| 成分 | 描述 |
| :--------- | :--------------------------------------------------------- |
| 脚本 | 使用 Python 编写的在 PC 上运行多人检测模型的测试脚本。 |
| 模型 | ONNX格式的原始CNN模型。 |
| 数据 | 测试图像和量化校准图像。 |
| 转换器 | 使用 Glow NN 进行 eIQ® 推理。 |
| 应用程序 | i.MX RT1170EVK 和 RT1060EVK 的 ML-Person-Detector 项目。 |
| 文档 | 实验室指南。 |
资源
- 购买受支持的主板。
- 安装MCUXpresso IDE v11.6.0+。
组装应用程序
您需要安装 Git 和West,然后执行以下命令来收集 ml-person-detector 的整个 SDK 交付。
west init -m https://github.com/nxp-mcuxpresso/appswpacks-ml-person-detector.git --mr mcux_release_github appswpacks-ml-person-detector
cd appswpacks-ml-person-detector
west update
构建并运行应用程序
要构建和运行应用程序,请参阅文档文件夹中的实验室指南或查看使用 MCUXpresso IDE 运行项目中的步骤。
PC 上的 ML-Person-Detector 验证
依赖包:
- opencv-python
- onnxruntime
- numpy
要使用验证工具,请转到脚本文件夹并运行以下命令。
图像测试
python image_test.py
视频测试
python video_test.py
模型部署
本节将使用 eIQ® Inference 和 Glow NN 实现提前编译,并将神经网络转换为目标文件。要遵循给定的部署步骤,您需要从eIQ-Glow下载 Glow 安装程序 并将其安装到转换器文件夹中。
模型分析
Glow 使用轮廓引导量化,通过推理提取神经网络中每个张量的可能数值的统计信息。请提前准备与输入分辨率相同的 png 格式图像。使用以下命令生成 yml 轮廓:
image-classifier.exe -input-image-dir=data/Calibration -image-mode=0to1 -image-layout=NCHW -image-channel-order=BGR -model=models/Onnx/dperson_shufflenetv2.onnx -model-input-name=input.1 -dump-profile=models/Glow/dperson_shufflenetv2.yml
然后你会在转换器文件夹下得到一个dperson_shufflenetv2.yml。
生成辉光束
捆绑包生成 (Bundle generation) 表示将模型编译为二进制目标文件 (bundle)。捆绑包生成使用模型编译器工具执行。
- 将 float32 模型编译为 int8 包:
model-compiler.exe -model=models/Onnx/dperson_shufflenetv2.onnx -model-input=input.1,float,[1,3,192,320] -emit-bundle=models/Glow/int8_bundle -backend=CPU -target=arm -mcpu=cortex-m7 -float-abi=hard -load-profile=models/Glow/dperson_shufflenetv2.yml -quantization-schema=symmetric_with_power2_scale -quantization-precision-bias=Int8
- 使用 CMSIS-NN 将 float32 模型编译为 int8 包:
model-compiler.exe -model=models/Onnx/dperson_shufflenetv2.onnx -model-input=input.1,float,[1,3,192,320] -emit-bundle=models/Glow/int8_cmsis_bundle -backend=CPU -target=arm -mcpu=cortex-m7 -float-abi=hard -load-profile=models/Glow/dperson_shufflenetv2.yml -quantization-schema=symmetric_with_power2_scale -quantization-precision-bias=Int8 -use-cmsis
量化模型验证
以下是两个量化模型精度验证的例子。虽然原始浮点模型和量化模型的输出在人体坐标上略有差异,但整体检测结果还是比较可靠的,精度也不错。
应用程序概述
人体检测演示项目分别基于恩智浦 MCU i.MX RT1170EVK 和 i.MX RT1060EVK 构建。众所周知,机器学习模型推理通常需要大量计算,而 MCU 通常只有一个核心。这意味着该核心不仅需要处理模型推理任务,还需要处理摄像头和显示部分。为了实时捕获摄像头图像并在显示屏上显示算法结果,我们基于 FreeRTOS 构建了一个基于微控制器的视觉智能算法 (uVITA) 系统。其结构如下所示。
其他参考应用
对于其他快速开发软件包,请访问应用软件包页面。
对于 SDK 示例,请转到MCUXpresso SDK并获取完整交付,以便能够构建和运行基于其他 SDK 组件的示例。
参考
- WIDER FACE:人脸检测基准
- https://github.com/dog-qiuqiu/FastestDet
- https://www.nxp.com/design/software/development-software/eiq-ml-development-environment/eiq-inference-with-glow-nn:eIQ-Glow )
来源:恩智浦appcodehub
331
