439 lines
22 KiB
Markdown
439 lines
22 KiB
Markdown
# PointNet
|
||
 <br> <br><br><br><a href="../../index.md#cv-cls" target="_blank"><img alt="模型清单" src="https://img.shields.io/badge/cv--cls-模型清单-cornflowerblue?logo=quicklook"></a><br>
|
||
|
||
# 下载
|
||
|
||
✨ 一键下载开发流程中所需的各种文件,包括编译使用的量化校准集、运行时工程的依赖库,以及输入输出文件。
|
||
|
||
💡 推荐使用linux版下载脚本,其wget包含断网自动重连功能,不会出现下载文件遗漏情况。
|
||
|
||
## windows
|
||
📌 第一次使用,请在C盘根目录下新建`icraft_auth.txt`,保存下载站账号密码,以换行符分隔
|
||
|
||
需要事先下载windows版本wget:
|
||
|
||
(若点击以下链接后未直接下载,请选择 ***1.20.3*** 版本下的对应系统链接进行下载)
|
||
|
||
[x86系统wget下载](https://eternallybored.org/misc/wget/1.20.3/32/wget.exe) [x64系统wget下载](https://eternallybored.org/misc/wget/1.20.3/64/wget.exe)
|
||
|
||
使用时需要将wget.exe的路径作为命令行参数传入,注意不是exe的父文件夹目录,而是包含wget.exe的完整绝对路径:
|
||
|
||
不下载Deps:`./download.ps1 "PATH_TO_WGET_EXE"`
|
||
|
||
如果您是第一次使用我们的模型库,请下载包括工程依赖库的所有文件:`./download.ps1 "PATH_TO_WGET_EXE" -d`
|
||
|
||
💡 下载过程中可能因网络问题出现中断情况,需 **自行重新运行** 下载脚本。
|
||
|
||
## linux
|
||
|
||
📌 第一次使用,请在/usr根目录下新建`icraft_auth.txt`,保存下载站账号密码,以换行符分隔
|
||
|
||
为确保文件格式正确,请在运行脚本前安装格式转换工具`dos2unix`,并执行格式转换命令:
|
||
```shell
|
||
sudo apt-get install dos2unix
|
||
dos2unix /usr/icraft_auth.txt
|
||
dos2unix ./download.sh
|
||
```
|
||
|
||
如果您是第一次使用我们的模型库,请下载包括工程依赖库的所有文件:`./download.sh -d`
|
||
|
||
如果之前已经在使用别的模型时下载过Deps依赖库,可以直接将其中的thirdparty部分复制到路径`3_deploy/Deps`,只需下载量化校准集和输入输出文件即可:`./download.sh`
|
||
|
||
|
||
🌟 Tips:
|
||
|
||
- 若想要直接获取原始weights和导出保存的模型,可分别前往 [weights](https://download.fdwxhb.com/data/04_FMSH-100AI/100AI/04_modelzoo/modelzoo_pub/weights/) 和 [fmodels](https://download.fdwxhb.com/data/04_FMSH-100AI/100AI/04_modelzoo/modelzoo_pub/compile/fmodels/) 网页上根据框架及模型名寻找并下载。
|
||
|
||
|
||
# 0. 文件结构说明
|
||
|
||
AI部署模型需要以下几部分文件
|
||
|
||
- 0_PointNet >模型原始工程,需要自行下载
|
||
- weights >存放原始权重,需要自行下载(本模型原始工程包含weights,因此无需准备)
|
||
- 1_scripts >若干脚本,用于保存Icraft编译器需要的模型、编译后仿真等功能
|
||
- 2_compile >Icraft编译器编译模型时所需要的文件
|
||
- 3_deploy >将Icraft编译器编译出的模型部署到硬件时需要的c++工程
|
||
|
||
# 1. python工程准备
|
||
|
||
## 1. **模型来源:**
|
||
|
||
- code:https://github.com/gchoi/PointNet.git
|
||
- branch:main
|
||
- commit_id:27caf22
|
||
- weights:https://github.com/gchoi/PointNet/blob/main/pretrained/pretrained-modelnet40.pth
|
||
|
||
## 2. **保存模型**
|
||
|
||
**目的:将模型保存成可以被Icraft编译器编译的形态**
|
||
|
||
1)原始weights位于`/0_PointNet/pretrained`文件夹中,如果不存在请手动下载至该文件夹
|
||
|
||
<div style="background-color: #FFFFCC; color: #000000; padding: 10px; border-left: 5px solid #FFA500;">
|
||
注意:
|
||
|
||
* 有时开源的weights url可能会变更。如果上述weights url失效,请根据原工程相应的branch以及commit版本寻找正确的下载链接
|
||
* 若上述weights url永久失效,请联系本模型库相关人员获取权限下载
|
||
</div>
|
||
|
||
2)根据模型来源中的地址,下载指定commit id版本的源代码,文件夹名称要设置为:0_PointNet
|
||
|
||
```shell
|
||
# 在此模型根目录
|
||
mkdir 0_PointNet
|
||
git clone -b main https://github.com/gchoi/PointNet.git 0_PointNet
|
||
cd 0_PointNet
|
||
git checkout 27caf22
|
||
```
|
||
|
||
3)进入1_scripts执行保存模型脚本
|
||
|
||
```shell
|
||
# 在此模型根目录
|
||
cd 1_scripts
|
||
python 1_save.py
|
||
```
|
||
|
||
**1_scripts提供脚本说明:**
|
||
|
||
- **环境要求:**Icraft编译器对**导出框架模型时**使用的**框架版本**有要求。即以下脚本中所有导出模型的脚本`1_save.py `,必须在要求的框架版本下执行,其他脚本不限制。要求的版本:
|
||
|
||
- **pytorch**:支持pytorch1.9.0、pytorch2.0.1两个版本的原生网络模型文件(.pt格式),以及pytorch框架保存为onnx(opset=17)格式的模型文件(.onnx格式)
|
||
- **paddle**:仅支持PaddlePaddle框架保存为onnx(opset=11)格式的模型文件(.onnx格式),不支持框架原生网络模型文件
|
||
- **darknet**:支持Darknet框架原生网络模型[GitHub - pjreddie/darknet: Convolutional Neural Networks](https://github.com/pjreddie/darknet)
|
||
- 0_infer.py >可以推理一张图并得到最终结果,模型原始权重会从 `/weights `中寻找,需要您预先下载
|
||
- 1_save.py >保存模型,保存好的用于Icraft编译器的模型,会存放在 `/2_compile/fmodel`
|
||
|
||
<div style="background-color: #FFFFCC; color: #000000; padding: 10px; border-left: 5px solid #FFA500;">
|
||
保存模型时的修改点:
|
||
|
||
1. 将logsoftmax操作用softmax等效<br>
|
||
</div>
|
||
|
||
- 2_save_infer.py >用修改后保存的模型做前向推理,验证保存的模型与原模型是否一致
|
||
- 3_sim_infer.py >用icraft编译后的模型做前向推理,验证编译模型的推理结果与原模型是否一致
|
||
- off2ftmp.py >将.off格式的原始点云数据转换为ftmp格式,作为网络输入的脚本
|
||
|
||
# 2.使用Icraft编译器编译模型
|
||
|
||
目的: 使用[Icraft编译器](https://gitee.com/mxh-spiger/icraft-introduction.git)将上一步保存好的**框架模型**转化为**硬件可部署模型**
|
||
|
||
- **1)相关命名说明:**
|
||
|
||
1)**fmodel**:frame model >用于Icraft编译器的框架模型
|
||
|
||
2)**imodel**:icraft model >用Icraft编译器编译出的模型
|
||
|
||
3)**qtset**:Quantitative Calibration Set >Icraft编译器所需的量化校准集
|
||
- **2)确认已安装正确的icraft版本**
|
||
|
||
检查方法:打开cmd运行:`icraft --version`
|
||
|
||
若已正常安装则会显示当前icraft版本,例如:
|
||
|
||
```
|
||
Icraft 版本:
|
||
* 3.7.1
|
||
|
||
CLI 版本:
|
||
3.7.0.0-a90988f(2412231401)
|
||
```
|
||
- 3)**执行编译:**
|
||
|
||
**在 `/2_compile`目录下执行编译:**
|
||
|
||
```shell
|
||
icraft compile config/pointnet_cls_8.toml
|
||
```
|
||
|
||
如果过程顺利,将得到 icraft model(以 `.json` (graph)`.raw`(param)的格式保存)
|
||
|
||
其中包括编译各阶段产生的中间结果模型和最终用于片上部署的BY模型,直接被保存到: 3_deploy/modelzoo/PointNet/imodel
|
||
|
||
|
||
# 3. 仿真
|
||
|
||
通过配置3_deploy/modelzoo/PointNet/cfg/中yaml文件的sim字段为True实现模型仿真。
|
||
|
||
```json
|
||
imodel:
|
||
...
|
||
sim: true
|
||
...
|
||
```
|
||
|
||
# 4. 部署模型
|
||
|
||
## 部署环境检查
|
||
|
||
* 以root账户登录片上系统terminal(ssh或串口皆可),模型库默认的模型存放路径为以下目录,如果没有请预先创建:
|
||
|
||
```
|
||
/home/fmsh/ModelZoo/
|
||
```
|
||
|
||
* 检查板上环境是否正确:
|
||
1. 查看环境变量,指令:
|
||
`icraft --version`
|
||
|
||
看打印信息是否如下:
|
||
|
||
```shell
|
||
Icraft 版本:
|
||
* v3.7.1
|
||
|
||
CLI 版本:
|
||
3.7.0.0-a90988f(2412231401)
|
||
```
|
||
|
||
2. 若是,在任意目录下输入`icraft-serve`即可打开server
|
||
|
||
3. 检查icraft和customop安装包版本是否为`arm64`
|
||
|
||
```shell
|
||
# 检查icraft安装包版本
|
||
dpkg -l | grep icraft
|
||
# 检查customop安装包版本
|
||
dpkg -l | grep customop
|
||
```
|
||
|
||
如果依次显示如下信息,则安装版本正确:
|
||
|
||
```shell
|
||
ii icraft 3.7.1 arm64 This is Icraft for arm64
|
||
ii customop 3.7.1 arm64 This is Icraft CustomOp for arm64
|
||
```
|
||
|
||
4. 如果环境配置有误,请参考[Part 1_1 2.3.1 片上系统环境 编译环境准备](https://gitee.com/mxh-spiger/tutorial-runtime/blob/tt3.7.1/docs/Part%201_1%20quick-start.md#1%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87-2)进行部署环境配置。
|
||
|
||
5. 根据此模型使用的硬算子,选择合适的位流,并在板上安装,所用硬算子及可选位流版本可参见本说明文档起始处的状态徽章,位流下载及安装说明请参考[1/4) 其他下载资源](https://gitee.com/mxh-spiger/icraft-introduction/tree/icraft_v3.7.1/#4%E5%85%B6%E4%BB%96%E4%B8%8B%E8%BD%BD%E8%B5%84%E6%BA%90)。
|
||
|
||
## python runtime:
|
||
|
||
|
||
目的:在AI硬件上执行模型前向推理
|
||
|
||
1. **python运行虚拟环境要求与准备**
|
||
|
||
- python版本:3.8(否则无法使用icraft的python API)
|
||
|
||
- 确保已安装icraft的python安装包
|
||
|
||
- socket模式使用:`pip install icraft-3.x.x-cp38-none-win_amd64.whl`
|
||
- axi模式使用:`pip install icraft-3.x.x-cp38-none-manylinux2014_aarch64.whl`
|
||
|
||
- 在选定的python运行虚拟环境中安装python运行时所需要的依赖包
|
||
|
||
```
|
||
cd 3_deploy/modelzoo/PointNet
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
- 安装一些便于开发pyrt的依赖包
|
||
|
||
```
|
||
cd 3_deploy/Deps/modelzoo
|
||
pip install -e .
|
||
```
|
||
|
||
<div style="background-color: #FFFFCC; color: #000000; padding: 10px; border-left: 5px solid #FFA500;">
|
||
由于python运行时代码在引入依赖包时候已经通过sys.path.append(R"../../../Deps/modelzoo")将一些便于开发pyrt的依赖包加入到了系统路径下,因此可以不用执行该步骤即可直接运行2.执行程序。这里提供额外的[pip install -e .]安装方式是为了在python运行时代码时候方便进行pyrtutils的依赖跳转。
|
||
|
||
2. **执行程序**
|
||
|
||
```
|
||
python ./PointNet.py ../cfg/pointnet_test.yaml
|
||
```
|
||
|
||
在io/output中查看结果
|
||
|
||
## c++ runtime:
|
||
|
||
目的:编译c/c++可执行程序,在AI硬件上执行模型前向推理
|
||
|
||
模型库以ubuntu操作系统为例:
|
||
|
||
1. **编译环境准备**
|
||
|
||
- os: ubuntu20.04
|
||
- cmake>=3.10
|
||
- compiler: aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc
|
||
2. **编译c++程序**
|
||
|
||
```shell
|
||
#在3.1所需的linux编译环境中
|
||
cd 3_deploy/modelzoo/PointNet/build_arm
|
||
cmake ..
|
||
make -j
|
||
```
|
||
|
||
4. **执行程序**
|
||
|
||
```
|
||
cd /home/fmsh/ModelZoo/modelzoo/PointNet/build_arm
|
||
chmod 777 *
|
||
./PointNet ../cfg/pointnet.yaml
|
||
```
|
||
|
||
在io/output中查看结果
|
||
|
||
# 5. 精度测试
|
||
|
||
<div style="background-color: #FFFFCC; color: #000000; padding: 10px; border-left: 5px solid #FFA500;">
|
||
由于精度测试需要遍历一个数据集中的所有图片,因此需要使用上位机作为主控操作系统(demo中是按windows作为上位机操作系统来做的),使用网口连接板子,运行时输入数据会通过上位机经由网口传到片上进行推理。
|
||
</div>
|
||
|
||
## 1. 环境准备
|
||
|
||
若已准备好环境请跳过此部分
|
||
|
||
**1. 网口调试环境准备**(如果已经准备好网口调试环境则看下一条)
|
||
|
||
1. 安装ssh
|
||
2. 查看或配置板子ip
|
||
|
||
- 使用串口连接板子
|
||
- `vim /etc/rc.local`
|
||
- 查看或设置ip
|
||
|
||
```
|
||
#!/bin/bash
|
||
ifconfig eth0 192.168.125.171 netmask 255.255.255.0
|
||
systemctl start sshd
|
||
```
|
||
3. 修改本地网络适配器配置
|
||
|
||
参考配置
|
||
|
||
- ipv4地址:`192.168.125.2`
|
||
- 子网掩码:`255.255.255.0`
|
||
- 默认网关:`192.168.125.1`
|
||
- 连接速度与双工:100mbps全双工
|
||
4. 使用网口或串口进入板上系统打开server
|
||
|
||
上位机:
|
||
|
||
```cmd
|
||
ssh root@192.168.125.171
|
||
```
|
||
|
||
板上:
|
||
确保位于root账户下,执行:
|
||
|
||
```shell
|
||
icraft-serve
|
||
```
|
||
|
||
* 请确保在root账户下执行上述命令
|
||
* 设备成功打开示意图
|
||
|
||
```
|
||
root@U:~# icraft-serve
|
||
[02/22/24 02:02:00.388] [I] Using port : 9981
|
||
[02/22/24 02:02:00.388] [I] synchronous mode
|
||
[02/22/24 02:02:00.388] [I] [irpc::port::tcp::_waitNewConn] wait for new connection
|
||
```
|
||
|
||
如果能正确运行则可以继续下一步。
|
||
|
||
**2.编译环境准备**
|
||
|
||
请参考[2.1Windows编译环境准备](https://gitee.com/mxh-spiger/tutorial-runtime/tree/rt3.0.0)进行精度测试环境配置。
|
||
|
||
- os: windows
|
||
- [cmake3.28](https://github.com/Kitware/CMake/releases/download/v3.28.1/cmake-3.28.1-windows-x86_64.msi)
|
||
- [visualstudio2022](https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&passive=false&cid=2030)
|
||
|
||
## 2. 测试说明
|
||
|
||
1. **如果使用了DetPost硬算子**(本模型未使用,请忽略此条)
|
||
|
||
- 1)修改customop toml
|
||
|
||
customop toml 即 config\customop\xxmodel.toml
|
||
|
||
需要将该文件中的 `thr_f`配置成0.001
|
||
|
||
```toml
|
||
[ImageMake]
|
||
no_imkpad = 0
|
||
|
||
[DetPost]
|
||
thr_f = 0.001 # 阈值
|
||
cmp_en = 1 # 是否做阈值比较
|
||
|
||
groups = 3
|
||
anchor_num = 3
|
||
position = 5
|
||
|
||
```
|
||
- 2)重新进行模型编译
|
||
|
||
```shell
|
||
icraft compile config/pointnet_cls_8.toml
|
||
```
|
||
|
||
由于测精度程序由上位机控制,生成的imodel不用再复制到板子中
|
||
2. **数据集准备**
|
||
|
||
* 测试数据集下载:[ModelNet40](http://modelnet.cs.princeton.edu/ModelNet40.zip)
|
||
* 模型测试使用ModelNet40数据集的Test部分,测试图片存放于 `1_scripts\Data\ModelNet40`中,数据集结构为:
|
||
```shell
|
||
├── airplane
|
||
│ ├── test
|
||
│ └── train
|
||
├── bathtub
|
||
│ ├── test
|
||
│ └── train
|
||
...
|
||
├── wardrobe
|
||
│ ├── test
|
||
│ └── train
|
||
└── xbox
|
||
├── test
|
||
└── train
|
||
```
|
||
|
||
* 数据集合法性处理:由于ModelNet40数据集在某些.OFF文件中缺少必要的空格或换行符导致读取文件失败,因此提供了修正脚本,位于`1_scripts/Data/ModelNet40Fixer/fixer.py`,请先运行此脚本处理下载好的ModelNet40数据集,再进行精度测试。
|
||
* 如需测试其他数据集,需自行将图片存放于上述路径,并准备对应的测试数据集
|
||
|
||
3. **修改 运行时的yaml配置文件**:
|
||
|
||
运行时需要配置一些模型路径,输入数据,后处理参数等,其配置文件在 `3_deploy/modelzoo/PointNet/cfg/`
|
||
|
||
测试时使用:`pointnet_test.yaml`
|
||
|
||
需要修改:
|
||
|
||
* imodel中参数:修改精度测试所用模型文件路径`dir`,根据所使用板子ip设置`ip`。
|
||
* dataset中参数:更改自己的精度测试数据集路径。
|
||
* param中参数:如果模型没有重训,则无需更改,若 重训则需要修改对应部分参数。
|
||
|
||
4. **编译、执行运行时程序**
|
||
|
||
python运行时:
|
||
* 首先请确保已经安装icraft对应版本的python API
|
||
* 其次安装运行pyrt脚本的依赖环境
|
||
```shell
|
||
cd 3_deploy/modelzoo/PointNet/pyrt
|
||
pip install requirement.txt
|
||
```
|
||
**执行运行时程序,计算出精度指标**
|
||
|
||
```shell
|
||
cd 3_deploy/modelzoo/PointNet/pyrt
|
||
python PointNet.py ../cfg/PointNet_test.yaml
|
||
```
|
||
|
||
|
||
|
||
|
||
# 6. 模型性能记录
|
||
|
||
| PointNet | input shape | hard time | qt_strategy | 精度 |
|
||
| -------------- | --------------- | -------------- | --------------- | ---------------- |
|
||
| float | [1, 3, 1024] | - | - | top-1:73.3(official:86.0) |
|
||
| int8 | [1, 3, 1024] | 0.841 ms | [kld-pc] | top-1:70.5 |
|
||
| int16 | [1, 3, 1024] | 1.814 ms | [kld-pc] | top-1:70.9 |
|