167 lines
12 KiB
Markdown
167 lines
12 KiB
Markdown
# ppo_lstm
|
||
 <br> <br><a href="../../index.md#drl" target="_blank"><img alt="模型清单" src="https://img.shields.io/badge/drl-模型清单-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_ppo_lstm >模型原始工程,需要自行下载
|
||
- weights >存放原始权重,需要自行下载
|
||
- 1_scripts >若干脚本,用于保存Icraft编译器需要的模型
|
||
- 3_deploy >将Icraft编译器编译出的模型部署到硬件时需要的c++工程
|
||
|
||
# 1. python工程准备
|
||
|
||
## 1. **模型来源:**
|
||
|
||
- code:https://github.com/DLR-RM/rl-baselines3-zoo.git
|
||
- branch:master
|
||
- commit_id:27e081e
|
||
- weights:https://download.fdwxhb.com/data/04_FMSH-100AI/100AI/04_modelzoo/modelzoo_pub/weights/pytorch/ppo_lstm
|
||
|
||
## 2. **保存模型**
|
||
|
||
**目的:将模型保存成可以被Icraft编译器编译的形态**
|
||
|
||
1)根据模型来源中的地址:
|
||
|
||
下载原始weights,存放于 `/weights`文件夹中
|
||
|
||
<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_ppo_lstm
|
||
|
||
```shell
|
||
# 在此模型根目录
|
||
mkdir 0_ppo_lstm
|
||
git clone -b master https://github.com/DLR-RM/rl-baselines3-zoo.git 0_ppo_lstm
|
||
cd 0_ppo_lstm
|
||
git checkout 27e081e
|
||
```
|
||
|
||
3)进入1_scripts执行保存模型脚本
|
||
|
||
```shell
|
||
# 在此模型根目录
|
||
cd 1_scripts
|
||
python 1_save.py
|
||
```
|
||
|
||
**1_scripts提供脚本说明:**
|
||
|
||
- 0_infer.py >可以推理一张图并得到最终结果,模型原始权重会从 `/weights `中寻找,需要您预先下载
|
||
- 1_save.py >保存模型与ONNX输入,保存为onnx模型,存放在:`\3_deploy\modelzoo\ppo_lstm\imodel` , 输出存放在:`\3_deploy\modelzoo\ppo_lstm\io`
|
||
- 2_save_infer.py >用修改后保存的模型做前向推理,验证保存的模型与原模型是否一致
|
||
|
||
|
||
# 2. 部署模型
|
||
|
||
目的:编译c/c++可执行程序,在硬件上执行onnxruntime进行前向推理
|
||
|
||
模型库以ubuntu操作系统为例:
|
||
|
||
1. **编译环境准备**
|
||
- os: ubuntu20.04
|
||
- cmake>=3.10
|
||
- compiler: aarch64-linux-gnu-g++/aarch64-linux-gnu-gcc
|
||
|
||
2. **版本依赖下载**
|
||
|
||
主要版本依赖已存放在`\3_deploy\modelzoo\ppo_lstm\onnxruntime`
|
||
|
||
相关文件:https://download.fdwxhb.com/data/04_FMSH-100AI/100AI/04_modelzoo/modelzoo_pub/pkgs/onnxruntime.zip
|
||
|
||
3. **编译c++程序**
|
||
|
||
```shell
|
||
#在3.1所需的linux编译环境中
|
||
cd 3_deploy/modelzoo/ppo_lstm/build_arm
|
||
|
||
cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -
|
||
DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++
|
||
|
||
make -j12
|
||
```
|
||
|
||
|
||
模型输入均在 `3_deploy/modelzoo/ppo_lstm/io`中,可根据需要进行替换,生成方式如下:
|
||
|
||
```
|
||
# 仅测试时间,python中随机生成输出
|
||
obs_onnx = torch.randn(1,2,64,64,dtype=torch.float32)
|
||
obs_onnx.tofile("encoder_input.ftmp")
|
||
...
|
||
# 最后手动放入对应3_deploy/modelzoo_v3.0.1/ppo_lstm/io/inputs/ppo_lstm目录中
|
||
```
|
||
|
||
5. **执行程序**
|
||
|
||
运行前需要手动把\3_deploy\modelzoo\ppo_lstm\onnxruntime\lib\aarch64下的libonnxruntime.so, libonnxruntime.so.1.17.1复制到运行环境中,例如 usr/lib下, 然后执行:
|
||
|
||
```
|
||
cd /home/fmsh/ModelZoo/modelzoo/ppo_lstm/build_arm
|
||
chmod 777 *
|
||
./ort_run
|
||
```
|
||
|
||
在终端可查看程序运行结果,显示最终输出耗时
|
||
|
||
|
||
|
||
|
||
# 3. 模型性能记录
|
||
|
||
onnxruntime在板上运行时间:
|
||
|
||
| ppo_lstm | input shape | hard time |
|
||
| -------------- | --------------- | -------------- |
|
||
| ppo_lstm | [1, 2, 64, 64],[1, 1, 128],[1, 1, 128] | 3.0ms |
|