PROFusion (ICRA 2026) 是一个用于实时相机跟踪与稠密场景重建的 RGB-D SLAM 系统。 本仓库基于官方 siyandong/PROFusion 代码, 将其 位姿回归模块(基于 PyTorch)迁移适配到华为昇腾 NPU, 并提供 HTTP 服务化推理 与完整测试用例。
profusion_pr-npu/
├── README.md # 本文档 (中文部署指引)
├── README_origin.md # 官方原始 README
├── requirements.txt # 昇腾 NPU 运行环境依赖
├── inference.py # ★ 服务化推理脚本 (Flask HTTP 服务)
├── test_inference.py # ★ 测试用例 (环境检查 + 模块级 + HTTP 端到端)
├── pose_regression/ # 位姿回归模块 (已适配 NPU)
│ ├── model.py # PROFusionPoseRegression 模型定义
│ ├── run.py # 模型加载 / 位姿回归流程
│ ├── inference.py # 推理辅助函数 rpr_inference
│ ├── modules/ # 编码器 / 多视图解码器 / 位姿头
│ └── utils/ # 设备 / 几何 / 图像工具
├── data_loader/ # 数据集加载器 (FemtoBolt / FastCaMo / ETH3D)
├── scripts/
│ ├── gen_screenshots.py # 交付截图生成脚本
│ └── adaptation_log.txt # 适配过程记录
└── assets/ # 交付截图
├── npu_device_call.png # NPU 设备调用截图
├── model_result.png # 测试结果截图
└── agent_workflow.png # 适配过程截图| 项目 | 要求 | 本机实测 |
|---|---|---|
| 硬件 | Ascend910 系列 (Atlas 800), ≥1 卡 | 12x Ascend910 (61 GB HBM) |
| OS | openEuler / Ubuntu / KylinOS (aarch64) | openEuler 22.03 SP4 aarch64 |
| CANN | ≥ 8.0 | 8.5.1 |
| Python | 3.8 – 3.11 | 3.11.14 |
| PyTorch | 2.9.0 | 2.9.0 |
| torch_npu | 与 PyTorch 配套 | 2.9.0.post1+gitee7ba04 |
# 1) 加载 CANN 环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 2) 指定可见 NPU 卡
export ASCEND_RT_VISIBLE_DEVICES=0
# 3) 安装依赖 (建议使用华为镜像源)
pip install -r requirements.txt \
-i https://repo.huaweicloud.com/repository/pypi/simple/
# 4) 校验 NPU 可用
python3 -c "import torch; import torch_npu; \
a = torch.randn(3, 4).npu(); print(a + a)" # 输出 device='npu:0' 即正常权重文件位置:
/mnt/old_data/whl/models/siyan824/profusion_pr/(model.safetensors与profusion_pr.pth均为同一套权重,二选一即可)
使用 ascend-model-agent-plugin 的 ai4s-basic(PyTorch 迁移)skill 完成,关键改动如下:
| 文件 | 原始 CUDA 代码 | 昇腾适配 |
|---|---|---|
pose_regression/utils/device.py | MyNvtxRange 调用 torch.cuda.synchronize() / torch.cuda.nvtx.* | 改为 NPU 同步 + NVTX no-op 兼容;并修复 todevice 对 dict 不原地移动张量 的缺陷 |
pose_regression/model.py | torch.amp.autocast('cuda', enabled=False) | 按实际设备动态选择 device_type(npu / cuda) |
pose_regression/modules/base_model.py | torch.backends.cuda.matmul.allow_tf32 = True | try/except 兼容 + NPU matmul 优化;新增 from_local_pretrained() 本地权重加载 |
pose_regression/run.py | PR.to('cuda')、to_device(view, device='cuda') | 设备参数化,get_device() 自动选择 npu:0 / cuda / cpu |
| curope (CUDA 扩展) | kernels.cu RoPE2D CUDA 算子 | 不编译,自动回退纯 PyTorch 版 RoPE2D(pos_embed.py 内建 fallback) |
详细适配过程见 scripts/adaptation_log.txt 与 assets/agent_workflow.png。
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
python3 inference.py \
--ckpt /mnt/old_data/whl/models/siyan824/profusion_pr/model.safetensors \
--port 8080 --device npu:0参数说明:
--ckpt:本地权重路径,支持.safetensors/.pth;缺省指向默认权重目录--device:推理设备,缺省自动选择npu:0(无 NPU 时回退 cuda/cpu)--port:HTTP 服务端口,默认 8080
GET /health — 健康检查
curl http://127.0.0.1:8080/health
# {"status":"ok","device":"npu:0","load_time":3.05}POST /infer — 相对位姿估计
输入:两帧 RGB-D 图像(reference 帧 + query 帧),图像与深度图为 base64 编码二进制:
{
"intrinsics": [fx, fy, cx, cy],
"frames": [
{"rgb_b64": "<uint8 RGB 图像 bytes>", "depth_b64": "<float32 深度图 bytes>", "h": 224, "w": 224},
{"rgb_b64": "<...>", "depth_b64": "<...>", "h": 224, "w": 224}
]
}输出:query 帧在 reference 帧坐标系下的相对位姿(4x4 齐次矩阵):
{
"status": "ok",
"pose": [[4x4 位姿矩阵]],
"rotation": [[3x3 旋转矩阵]],
"translation": [x, y, z],
"elapsed": 0.06,
"total_elapsed": 0.10
}约束:图像宽高需为 16 的整数倍(与 patch_size 对齐),深度单位为米(m), 平移输出单位为米,乘以 1000 即毫米。
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
python3 test_inference.py \
--ckpt /mnt/old_data/whl/models/siyan824/profusion_pr/model.safetensors \
--device npu:0测试覆盖:
infer_relative_pose()POST /infer 端到端验证[env] NPU[0] : Ascend910_9382, 显存 61 GB
[inference] 模型加载完成: 540.6M 参数, 设备 npu:0, 耗时 3.05s
[module] 相对位姿:
[[ 0.99993 -0.00935 0.00773 -0.18337]
[ 0.0095 0.99975 -0.02014 0.10296]
[-0.00754 0.02021 0.99977 -0.26872]
[ 0. 0. 0. 1. ]]
[module] 旋转行列式 : 1.000001 (PASS, 应≈1)
[module] 平移(毫米) : [-183.4 103.0 -268.7] (PASS, 非零)
[http] HTTP 状态 : 200
[http] 推理耗时 : 0.0589 s (热推理, 已含算子编译缓存)torch_npu.npu_fusion_attention 替换自注意力,
或对编码器部分使用 bf16 混合精度(位姿头需保持 fp32)。
注意:位姿头的 SVD 正交化(torch.svd / torch.det)在 NPU 上会
CPU fallback(仅影响毫秒级耗时,不影响精度),属已知现象。optimization_fusion(见官方仓库 build.sh),不在本迁移范围内。hccl 并
使用 torchrun --nproc_per_node=N inference.py ...。@article{dong2025profusion,
title={PROFusion: Robust and Accurate Dense Reconstruction via Camera Pose Regression and Optimization},
author={Dong, Siyan and Wang, Zijun and Cai, Lulu and Ma, Yi and Yang, Yanchao},
journal={arXiv preprint arXiv:2509.24236},
year={2025}
}许可证:CC BY-NC-SA 4.0(非商业使用)