基于Qualcomm Robotics RB5边缘侧AI应用—人群热力图

4 篇文章 0 订阅

该解决方案将使用IP摄像头、基于高通®Robotics RB5 Edge AI设备的实时输入流分析和计算机视觉系统。解决方案提供了一个端到端的应用程序,可以快速集成到新的构建系统中。相关代码可以在这里获取到:

https://github.com/quic/sample-apps-for-robotics-platforms/tree/master/RB5/linux_kernel_5_x/AI-ML-apps/AI_Heatmap_Solutions

所需使用硬件设备

  1. An Ubuntu 20.04 PC
  2. Qualcomm Robotics RB5 Development kit: https://developer.qualcomm.com/qualcomm-robotics-rb5-kit​
  3. A USB camera
  4. A display monitor 

相关环境配置

1. 前提条件

2. x86 Host Installation and Deep Learning Model Compile

应用程序中使用的模型需要使用数据集进行训练。然后将模型转换为dlc以在应用程序中运行。

2.1 Qualcomm® Neural Processing SDK Installation

Download Qualcomm® Neural Processing Software Development Kit (SDK) from Qualcomm Neural Processing SDK for AI Tools & Resources Archive - Qualcomm Developer Network.

高通神经处理SDK提供了用于模型转换(onnx到dlc)、模型量化和执行的工具。请参阅SDK中详细文档中给出的步骤进行安装. Snapdragon Neural Processing Engine SDK: Main Page

2.2 准备Yolov5 AI模型

按照 ModelPreperation.md 导出和编译Yolov5模型。

下载人员检测预训练YoloV5模型https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5s.pt

对于头盔和头部检测,需要在数据集上训练模型。头盔和头部检测数据集可以从Kaggle下载。

Safety Helmet Detection | Kaggle

2.3 Export *.pt file to ONNX file

建议安装Python 3.6.9版本。下载Yolov5 v6.0源代码

wget https://github.com/ultralytics/yolov5/archive/refs/tags/v6.0.tar.gz
tar -zxvf v6.0.tar.gz
cd yolov5-6.0
wget https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5s.pt

Python要求:

  • python 3.6.9
  • protobuf==3.17.3
  • onnx==1.9.0
  • onnx-simplifier==0.2.6
  • onnxoptimizer==0.2.6
  • onnxruntime==1.1.0
  • numpy==1.16.5
  • torch==1.10.0
  • torchvision==0.11.1
sudo apt install python3.6 python3.6-venv build-essential make python3-dev python3.6-dev protobuf-compiler libprotobuf-dev
python3.6 -m pip install --upgrade pip
python3.6 -m pip install -r requirements.txt
python3.6 -m pip install coremltools>=4.1 onnx==1.9.0 scikit-learn==0.19.2 onnxruntime==1.1.0 onnx-simplifier==0.2.6 onnxoptimizer==0.2.6

将YoloV5导出到ONNX:

python3.6 export.py --weights yolov5s.pt --optimize --opset 11 --simplify --include onnx -imgsz [416,416]

3. 将Onnx模型转换为DLC

3.1 设置SNPE

需要设置SNPE将onnx模型转换为量化的dlc,请使用提供的链接按照说明设置神经处理SDK。请在整个演示过程中使用相同版本的SNPE. https://developer.qualcomm.com/docs/snpe/setup.html

export SNPE_ROOT=<path to snpe folder>/snpe-1.68.0.3932
export ANDROID_NDK_ROOT=<path to android ndk folder>

从pip查找onnx安装路径

python3.6 -m pip show onnx

在上述命令的输出中查找“Location:”行

export ONNX_DIR=<path from Location line>/onnx

为snpe设置onnx环境

cd $SNPE_ROOT
source bin/envsetup.sh -o $ONNX_DIR

SNPE目前不支持5D运算符。它要求在转换命令中的5D重塑之前指定输出节点。可以在Netron中检查输出节点。

要检查输出层节点,请在Netron应用程序中打开模型,然后单击Conv层。

在附加的快照中,5D之前的输出节点为onnx::326(Conv_198)、365(Conv_216)和404(Conv_334)

此实现具有以下功能:

  • anchorBoxProcess: Get raw data from out nodes before 5D (Conv_198, Conv_216, Conv_234), convert to meaning data (scores, class, bounding boxes).
  • doNMS: (non-max suppression): remove overlap boxes
  • ShowDetectionOverlay: Overlay detection result at output video/Image

3.2 转换为DLC

snpe-onnx-to-dlc -i yolov5s.onnx --out_node <output name 1> --out_node <output name 2> --out_node <output name 3>

与上面的屏幕截图相对应的示例:

snpe-onnx-to-dlc -i yolov5s.onnx --out_node 326 --out_node 365 --out_node 404

3.3 生成AIP/DSP的量化模型

使用设备中安装的相同高通®神经处理SDK版本。请参考模型目录中给出的inputlist.txt文件。根据您的yolov5s.onnx模型创建您自己的inputlist.txt文件。我们需要更新inputlist.txt中的所有输出名称

snpe-dlc-quantize --input_dlc=yolov5s.dlc --input_list=inputlist.txt --output_dlc=yolov5s_quant.dlc --enable_hta 

模型量化需要input.raw文件。使用以下python命令创建一个示例input.raw文件。

import numpy as np
((np.random.random((1,3,640,640)).astype(np.float32))).tofile("input.raw")

4. X86 Host RTSP Stream Installation

在本节中,演示如何准备测试视频并设置live555 RTSP流媒体服务器以模拟IP摄像机。安装步骤在X86主机中运行。

4.1 准备测试视频

如果测试视频是mp4、mkv或其他格式,请准备一个测试视频。需要转换为H264原始视频。以下步骤演示如何将MP4转换为H264原始视频。

wget https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_1MB.mp4
sudo apt install ffmpeg
ffmpeg -i Big_Buck_Bunny_1080_10s_1MB.mp4 -f h264 -vcodec libx264 Big_Buck_Bunny_1080_10s_1MB.264

4.2 Live555服务器安装

wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz
tar -zxvf live555-latest.tar.gz
cd live/
./genMakefiles linux-64bit
make -j4
cd ..

将测试视频复制到mediaServer文件夹

cp Big_Buck_Bunny_1080_10s_1MB.264 ./live/mediaServer
cd ./live/mediaServer
./live555MediaServer

rtsp://192.168.4.111:8554/ is the rtsp url.

  • "192.168.4.111" is RTSP server IP address
  • 8554 is the default port
  • is the video file name under mediaServer folder In this case, url "rtsp://192.168.4.111:8554/Big_Buck_Bunny_1080_10s_1MB.264" is the video address.

4.3 验证live555服务器

在Windows桌面上下载并安装VLC媒体播放器VLC: Official site - Free multimedia solutions for all OS! - VideoLAN

Launch VLC player, choose "Media->Open Network Stream" input RTSP url rtsp://192.168.4.111:8554/Big_Buck_Bunny_1080_10s_1MB.264

单击播放以测试live555服务器是否正常工作。注意:确保网络地址可访问

如何配置、构建和运行此人群热力检测应用程序

1. 克隆存储库

adb shell

cd /home/
apt install git
git clone https://github.com/quic/sample-apps-for-robotics-platforms.git
cd sample-apps-for-robotics-platforms/RB5/linux_kernel_5_x/AI-ML-apps/AI_Heatmap_Solutions/

2. 更新应用程序配置

所有解决方案的配置在data/config.json文件中进行了描述。应更新此配置文件以选择所需的解决方案、模型配置和输入/输出流。应用程序可以将rtsp/camera流作为输入,并将输出转储到mp4或hdmi监视器。

Table 1-1 show all the configuration items:

输入配置

key

Value

Description

input-config-name

string

Name of the input config

stream-type

string

Input stream type camera or rtsp

stream-width

int

Width of the input stream

stream-height

int

Height of the input stream

SkipFrame

int

Numer of frames to skip

camera-url

string

rtsp stream path if the input stream is rtsp

模型配置

key

Value

Description

model-name

string

Name of the model

model-path

string

Path of the dlc file

label-path

string

Path of the label file

runtime

string

SNPE Runtime (GPU, CPU, DSP)

nms-threshold

float

NMS threshold

conf-threshold

float

Confidence threshold

labels

int

Number of labels + 5

input-layers

string

Name of the input layers

output-layers

string

Name of the output layers

output-tensors

string

Name of the output tensors

解决方案配置

key

Value

Description

solution-name

string

Name of the Solution

model-name

string

Name of the model configuration to be used

input-config-name

string

Name of the Input configuration to be used

Enable

bool

1 to Enable and 0 to Disable the solution

output-type

string

Filesink to save the output in mp4

Wayland if display the output on hdmi monitor

output-path

string

Path of the output, Enabled if output type

is filesink

Example 1: 从相机获取输入流并在hdmi监视器上输出的配置

{
    "input-configs":[
        {
            "input-config-name":"camera",
            "stream-type":"camera",
            "stream-width":1280,
            "stream-height":720,
            "SkipFrame":1,
            "fps-n":30,
            "fps-d":1
        },
 ],
     "model-configs":[
        {
            "model-name":"yolov5s-1",
            "model-path":"../models/heatmap_detection.dlc",
            "label-path":"../data/coco_label.txt",
            "runtime":"DSP",
            "labels":85,
            "grids":25200,
            "nms-threshold":0.5,
            "conf-threshold":0.5,
            "input-layers":[
                "images"
            ],
            "output-layers":[
                "Conv_271",
                "Conv_305",
                "Conv_339"
            ],
            "output-tensors":[
                "443",
                "496",
                "549"
            ],
            "global-threshold":0.2
        },
 ],
     "solution-configs":[
        {
            "solution-name":"heatmap-detection",
            "model-name":"yolov5s-1",
            "input-config-name":"camera",
            "Enable":0,
            "strict_area_x":10,
            "strict_area_y":10,
            "strict_area_w":1000,
            "strict_area_h":1000,
            "output-type":"wayland",
        },
 ],
 }
 

Example 2: 设备上rtsp输入流和输出的配置

"input-configs":[
    {
        "input-config-name":"rtsp3",
        "stream-type":"rtsp",
        "camera-url":"rtsp://10.147.243.253:8554/heatmap_video.264",
        "SkipFrame":1
    },
        
"model-configs":[
    {
        "model-name":"yolov5s-3",
        "model-path":"../models/heatmap_detection.dlc",
        "label-path":"../data/coco_labels.txt",
        "runtime":"DSP",
        "nms-threshold":0.1,
        "conf-threshold":0.1,
        "labels":6,
        "grids":25200,
        "input-layers":[
            "images"
        ],
        "output-layers":[
            "/model.24/m.0/Conv",
            "/model.24/m.1/Conv",
            "/model.24/m.2/Conv"
        ],
        "output-tensors":[
            "/model.24/m.0/Conv_output_0",
            "/model.24/m.1/Conv_output_0",
            "/model.24/m.2/Conv_output_0"
        ],
        "global-threshold":0.2
    },
 
"solution-configs":[
    {
        "solution-name":"heatmap-solution",
        "model-name":"yolov5s-3",
        "input-config-name":"rtsp3",
        "Enable":1,
        "output-type":"filesink",
        "output-path":"/root/crack.mp4"
    },
]
 
Use model-name and input-config-name to select model and input stream respectively.

3. 模型集成

将model推送到应用程序中的model目录中,并更新config.json文件。

更新输出层和输出张量。要检查输出层和输出张量节点,请在Netron应用程序中打开模型,然后单击图像中提到的Conv层。

 

在yolov5s.onnx中,5D之前的输出层是onnx::326(Conv_198)、365(Conv_216)和404(Conv_34),输出张量是Conv_198Conv_216Conv_234。

  "model-configs":[
      {
          "model-name":"yolov5s-1", --> Add model name here. It should match with the model name in solution config
          "model-type":"yolov5", --> It should be yolov5 for YoloV5 model.
          "model-path":"../models/yolov5.dlc", --> Path of the quantized model
          "label-path":"../data/label.txt", --> Path to the label file
          "runtime":"DSP", 
          "labels":8, --> Update label here. it should be 5 + {number of classes}. If nc = 3 then labels = 8
          "grids":25200,
          "nms-threshold":0.5,
          "conf-threshold":0.4,
          "input-layers":[
              "images" --> Open the model in netron.app and get the input-layers names.
          ],
          "output-layers":[ --> Refer the steps given above to know the output-layers and output-tensors
              "Conv_198",
              "Conv_216",
              "Conv_234"
          ],
          "output-tensors":[
              "326",
              "365",
              "404"
          ],
          "global-threshold":0.2
      },

4. 在目标设备上下载和部署SNPE库的步骤

Download Qualcomm Neural Processing Software Development Kit (SDK) from Qualcomm Neural Processing SDK for AI Tools & Resources Archive - Qualcomm Developer Network.

Windows

cd snpe-1.68.0\snpe-1.68.0.3932
adb push lib\aarch64-ubuntu-gcc7.5\. /usr/lib/
adb push lib\aarch64-ubuntu-gcc7.5\libsnpe_dsp_domains_v2.so /usr/lib/rfsa/adsp/
adb push lib\dsp\. /usr/lib/rfsa/adsp/
adb push bin\aarch64-ubuntu-gcc7.5\snpe-net-run /usr/bin/

Linux

cd snpe-1.68.0/snpe-1.68.0.3932/
adb push lib/aarch64-ubuntu-gcc7.5/* /usr/lib/
adb push lib/aarch64-ubuntu-gcc7.5/libsnpe_dsp_domains_v2.so /usr/lib/rfsa/adsp/
adb push lib/dsp/* /usr/lib/rfsa/adsp/
adb push bin/aarch64-ubuntu-gcc7.5/snpe-net-run /usr/bin/

Verify SNPE version

adb shell
chmod +x /usr/bin/snpe-net-run
snpe-net-run --version

5. 执行应用程序的步骤

5.1 安装 OpenCV 4.5.5

下载OpenCV 4.5.5源代码

https://codeload.github.com/opencv/opencv/tar.gz/refs/tags/4.5.5

adb shell
wget https://codeload.github.com/opencv/opencv/tar.gz/refs/tags/4.5.5 -O opencv-4.5.5.tar.gz
tar  -zxvf opencv-4.5.5.tar.gz
cd ./opencv-4.5.5

安装依赖项

apt install build-essential cmake unzip git pkg-config
apt install libjpeg-dev libpng-dev libtiff-dev
apt-get install libjsoncpp-dev libjson-glib-dev libgflags-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
apt install libjasper-dev
apt-get install libeigen3-dev

如果你收到一个关于libjasper-dev丢失的错误,请按照以下说明进行操作:

wget http://ports.ubuntu.com/ubuntu-ports/pool/main/j/jasper/libjasper-dev_1.900.1-debian1-2.4ubuntu1.3_arm64.deb
dpkg -i libjasper-dev_1.900.1-debian1-2.4ubuntu1.3_arm64.deb
wget http://ports.ubuntu.com/ubuntu-ports/pool/main/j/jasper/libjasper1_1.900.1-debian1-2.4ubuntu1.3_arm64.deb
dpkg -i libjasper1_1.900.1-debian1-2.4ubuntu1.3_arm64.deb

否则(如果已经安装libjasper-dev), 继续执行:

apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
apt install libxvidcore-dev libx264-dev

OpenCV的highgui模块依赖于GTK库进行GUI操作。安装GTK命令:

apt install libgtk-3-dev

安装Python 3头文件和库

apt install libatlas-base-dev gfortran
apt install python3.6-dev

Build and install

mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5 \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_GENERATE_PKGCONFIG=YES \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D BUILD_EXAMPLES=OFF \
      -D INSTALL_PYTHON_EXAMPLES=OFF \
      ..
make -j8
make install      

5.2 构建应用程序

adb shell
cd /home/sample-apps-for-robotics-platforms/RB5/linux_kernel_5_x/AI-ML-apps/AI_Heatmap_Solution/
mkdir build 
cd build
cmake -DSNPE_SDK_BASE_DIR=<SDK Directory Path>/snpe-1.68.0.3932 ..
make

5.3 运行应用程序

在监视器上显示输出。请通过HDMI电缆将显示器连接到设备。按照以下说明启用weston:

export XDG_RUNTIME_DIR=/run/user/root
cd build
./out/main -c ../data/config.json

验证结果

如果输出类型为filesink,请检查“输出路径”的目录是否为filesink。或者,请检查与HDMI连接的显示器的输出。

作者:廖洋洋,高通工程师

  • 19
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
完整版:https://download.csdn.net/download/qq_27595745/89522468 【课程大纲】 1-1 什么是java 1-2 认识java语言 1-3 java平台的体系结构 1-4 java SE环境安装和配置 2-1 java程序简介 2-2 计算机中的程序 2-3 java程序 2-4 java类库组织结构和文档 2-5 java虚拟机简介 2-6 java的垃圾回收器 2-7 java上机练习 3-1 java语言基础入门 3-2 数据的分类 3-3 标识符、关键字和常量 3-4 运算符 3-5 表达式 3-6 顺序结构和选择结构 3-7 循环语句 3-8 跳转语句 3-9 MyEclipse工具介绍 3-10 java基础知识章节练习 4-1 一维数组 4-2 数组应用 4-3 多维数组 4-4 排序算法 4-5 增强for循环 4-6 数组和排序算法章节练习 5-0 抽象和封装 5-1 面向过程的设计思想 5-2 面向对象的设计思想 5-3 抽象 5-4 封装 5-5 属性 5-6 方法的定义 5-7 this关键字 5-8 javaBean 5-9 包 package 5-10 抽象和封装章节练习 6-0 继承和多态 6-1 继承 6-2 object类 6-3 多态 6-4 访问修饰符 6-5 static修饰符 6-6 final修饰符 6-7 abstract修饰符 6-8 接口 6-9 继承和多态 章节练习 7-1 面向对象的分析与设计简介 7-2 对象模型建立 7-3 类之间的关系 7-4 软件的可维护与复用设计原则 7-5 面向对象的设计与分析 章节练习 8-1 内部类与包装器 8-2 对象包装器 8-3 装箱和拆箱 8-4 练习题 9-1 常用类介绍 9-2 StringBuffer和String Builder类 9-3 Rintime类的使用 9-4 日期类简介 9-5 java程序国际化的实现 9-6 Random类和Math类 9-7 枚举 9-8 练习题 10-1 java异常处理 10-2 认识异常 10-3 使用try和catch捕获异常 10-4 使用throw和throws引发异常 10-5 finally关键字 10-6 getMessage和printStackTrace方法 10-7 异常分类 10-8 自定义异常类 10-9 练习题 11-1 Java集合框架和泛型机制 11-2 Collection接口 11-3 Set接口实现类 11-4 List接口实现类 11-5 Map接口 11-6 Collections类 11-7 泛型概述 11-8 练习题 12-1 多线程 12-2 线程的生命周期 12-3 线程的调度和优先级 12-4 线程的同步 12-5 集合类的同步问题 12-6 用Timer类调度任务 12-7 练习题 13-1 Java IO 13-2 Java IO原理 13-3 流类的结构 13-4 文件流 13-5 缓冲流 13-6 转换流 13-7 数据流 13-8 打印流 13-9 对象流 13-10 随机存取文件流 13-11 zip文件流 13-12 练习题 14-1 图形用户界面设计 14-2 事件处理机制 14-3 AWT常用组件 14-4 swing简介 14-5 可视化开发swing组件 14-6 声音的播放和处理 14-7 2D图形的绘制 14-8 练习题 15-1 反射 15-2 使用Java反射机制 15-3 反射与动态代理 15-4 练习题 16-1 Java标注 16-2 JDK内置的基本标注类型 16-3 自定义标注类型 16-4 对标注进行标注 16-5 利用反射获取标注信息 16-6 练习题 17-1 顶目实战1-单机版五子棋游戏 17-2 总体设计 17-3 代码实现 17-4 程序的运行与发布 17-5 手动生成可执行JAR文件 17-6 练习题 18-1 Java数据库编程 18-2 JDBC类和接口 18-3 JDBC操作SQL 18-4 JDBC基本示例 18-5 JDBC应用示例 18-6 练习题 19-1 。。。
基于Matlab Robotics Toolbox开发的Dobot机械臂运动规划主要包括以下几个步骤。 首先,通过加载Robotic Toolbox库,将Dobot机械臂的模型导入Matlab环境。这个模型包含机械臂的几何参数、关节角度范围和DH参数等信息。 接下来,定义机械臂的初始和目标位姿。通过将关节角度或末端执行器的位姿作为输入,确定机械臂的起始和目标状态。 然后,使用机械臂的运动学模型,计算机械臂各个关节的位姿,以及末端执行器的位姿。 接下来,选择适合的规划方法,例如基于关节空间或笛卡尔空间的规划方法。基于关节空间的规划方法通过优化关节角度来实现运动,而基于笛卡尔空间的规划方法则优化末端执行器的位姿。 在规划过程中,可以使用机械臂的约束和目标函数来指导规划过程。例如,可以设置关节角度的范围限制、碰撞检测和路径长度最小化等约束条件。 最后,使用规划器生成机械臂的运动轨迹。通过实时控制机械臂的关节角度或末端执行器的位姿,实现机械臂的运动控制。 需要注意的是,在进行机械臂运动规划时,需要考虑机械臂的动力学特性、物理约束和控制方法等因素,以确保运动的正确性和安全性。 总结来说,基于Matlab Robotics Toolbox的Dobot机械臂运动规划的关键步骤包括导入机械臂模型、定义初始和目标位姿、计算机械臂的各个关节和末端执行器的位姿、选择规划方法、设置运动约束和目标函数,以及生成机械臂的运动轨迹。这些步骤可以帮助实现Dobot机械臂的运动规划和控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值