---
title: flightmare_pipeline
canonical_url: "https://www.modelscope.cn/models/AIBS/flightmare_pipeline"
md_url: "https://www.modelscope.cn/models/AIBS/flightmare_pipeline.md"
repository: AIBS/flightmare_pipeline
chinese_name: "无人机野外飞行"
last_updated: 2026-01-19
pipeline_tag: robotics
tasks:
  - robotics
library_name:
  - onnx
  - other
frameworks:
  - other
downloads: 2
stars: 0
---

# flightmare_pipeline

> flightmare_pipeline - AIBS 在 ModelScope 开源的模型。flightmaresln（Windows + iCraft / ZG330）

- **Repository**: AIBS/flightmare_pipeline
- **Tasks**: robotics
- **Downloads**: 2
- **Stars**: 0
- **Last updated**: 2026-01-19

Source: https://www.modelscope.cn/models/AIBS/flightmare_pipeline

---

# flightmare_sln（Windows + iCraft / ZG330）

这个工作区用于把 **Agile Autonomy / Flightmare** 的 PlannerLearning 网络导出为 ONNX，并通过 **iCraft 工具链**编译到 **@zhuget(330)**（ZG330），最后在设备上跑一次推理并与 ONNXRuntime（CPU）结果做数值对比。

如果你需要“原始算法/训练/仿真”的完整说明，请看上游仓库文档：

- 论文/数据/Ubuntu+ROS 安装：`0_flighmare_sln/agile_autonomy/README.md`

本 README 重点描述：**本工程在 Windows 下的导出/编译/部署/推理验证链路**。

---

## 目录结构

- `0_flighmare_sln/`

  - `agile_autonomy/`：上游代码（PlannerLearning 网络定义、配置等）
  - `standalone/` 与 `standalone.7z`：Flightmare standalone 相关资源（用于仿真/渲染，是否需要取决于你的使用场景）
- `1_scripts/`

  - `1_save.py`：从 PlannerLearning 导出 `flightmare.onnx`
  - `2_save_infer.py`：加载 iCraft 编译产物，在设备跑一次 forward，并与 ONNXRuntime 做对比
- `2_compile/`

  - `config/flightmare.toml`：iCraft 工具链配置（parse/optimize/quantize/adapt/generate）
  - `fmodel/flightmare.onnx`：导出的 ONNX（输入为 depth + imu）
  - `qtset/flightmare/`：量化校准输入样本（`depth.bin`、`imu.bin`）
  - `qtset/flightmare.txt`：校准样本列表（默认 `depth.bin;imu.bin`）
  - `imodel/flightmare/`：iCraft 中间与最终产物（含 `flightmare_ZG.json` / `flightmare_ZG.raw`）
- `3_deploy/`

  - `io/io_*/io.pkl`：推理输入/输出样本。`2_save_infer.py` 会自动挑最新的一个做单次验证
- `results/time_results/`

  - `*.xlsx`：如果开启 profile，会导出一次推理的统计信息

---

## 快速开始（导出 → 编译 → 部署 → 对比）

### 0) 前置条件

你需要具备两类 Python 依赖：

1) **导出 ONNX**（TensorFlow + tf2onnx）

- `tensorflow`（脚本内是 TF2 风格）
- `tf2onnx`

2) **推理对比**（ONNXRuntime + iCraft Python SDK）

- `onnxruntime`
- `numpy`
- iCraft Python SDK：`icraft.*`、`pyrtutils.*`

---

### 1) 导出 ONNX（生成 2_compile/fmodel/flightmare.onnx）

脚本：`1_scripts/1_save.py`

你需要检查并按你本机路径修改三个常量：

- `PLANNER_ROOT`：指向 `0_flighmare_sln/agile_autonomy/planner_learning`
- `SETTINGS_FILE`：指向 `planner_learning/config/test_settings.yaml`
- `OUTPUT_FILE`：默认输出到 `2_compile/fmodel/flightmare.onnx`

运行（PowerShell 示例）：

```powershell
python .\1_save.py
```

导出的 ONNX 关键点：

- 输入是一个 dict：
  - `depth`: shape `[1, seq_len, 224, 224, 3]`, dtype `float32`
  - `imu`: shape `[1, seq_len, 21]`, dtype `float32`
- `seq_len` 来自 `settings.seq_len`，脚本会用该值构造 dummy input

---

### 2) 准备量化/校准样本（qtset）

量化配置在 `2_compile/config/flightmare.toml`：

- `forward_dir = "./qtset/flightmare"`
- `forward_list = "./qtset/flightmare.txt"`

当前仓库已包含示例样本：

- `2_compile/qtset/flightmare/depth.bin`
- `2_compile/qtset/flightmare/imu.bin`
- `2_compile/qtset/flightmare.txt` 内容为 `depth.bin;imu.bin`

如果你替换样本：

- 请确保二进制内容与模型输入布局/shape一致
- 同时更新 `flightmare.txt`

---

### 3) iCraft 编译（生成 imodel/flightmare/flightmare_ZG.json + .raw）

编译配置入口：`2_compile/config/flightmare.toml`

该配置会从：

- `2_compile/fmodel/flightmare.onnx`

经过 parse/optimize/quantize/adapt/generate，最终落盘到：

- `2_compile/imodel/flightmare/flightmare_ZG.json`
- `2_compile/imodel/flightmare/flightmare_ZG.raw`

> 由于 iCraft 工具链在不同版本/发行包里 CLI 命令可能不同，本仓库不在 README 里写死具体命令。
> 你只需要在 iCraft 工具里指定该 toml，按顺序执行对应阶段即可。

---

### 4) 设备推理 + ONNXRuntime 对比（单次）

脚本：`1_scripts/2_save_infer.py`

它会：

1) 自动在 `3_deploy/io/` 下找到最新的 `io/io_*/io.pkl`
2) 从 `io.pkl` 读取输入：`inputs.depth` 与 `inputs.imu`
3) 加载 iCraft 编译产物 `flightmare_ZG.json/.raw` 并在设备跑一次 `session.forward()`
4) 用 ONNXRuntime（CPU）跑同一份输入
5) 输出数值误差：MAE / MaxAbs
6) 如果 `io.pkl` 里带有 `predictions`（通常来自 TF），也会同时对比 iCraft/ONNX vs TF

运行前你通常需要根据现场修改：

- `DEVICE_IP`：设备 IP（默认 `192.168.125.92`）
- `RUN_BACKEND`：`host` 或其它后端（取决于你的 iCraft 环境）
- `ENABLE_TIME_PROFILE` / `USE_CALCTIME_DETAIL`：是否导出 profile（输出到 `results/time_results/`）

运行（PowerShell 示例）：

```powershell
python .\2_save_infer.py
```

输出示例（字段含义）：

- `[TIMING]`：一次 `session.forward()` 的 wall time
- `[ACC] iCraft vs ONNX`：iCraft 输出与 ONNXRuntime 输出的误差
- `[ACC] * vs TensorFlow`：如果样本里有 `predictions`，会额外对比

---

## io.pkl 数据格式约定

`3_deploy/io/io_*/io.pkl` 期望包含（最小集合）：

```python
{
	"inputs": {
		"depth": np.ndarray(float32),
		"imu": np.ndarray(float32),
	},
	# 可选：用于对齐参考
	"predictions": np.ndarray(float32),
}
```

其中 `depth/imu` 的 shape 必须与导出的 ONNX 输入一致。

---

## 备注

- `0_flighmare_sln/agile_autonomy` 是上游工程（Ubuntu/ROS 生态），本仓库的 Windows 部分主要用于导出 ONNX 与 iCraft 侧验证。
- `ros_cuda.zip.*` 与 `standalone.7z` 属于大体积依赖/资源包，建议使用 7-Zip 等工具解压（分卷请从 `.001` 开始解压）。
