liuhongwei-2026/profusion_pr
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

siyan824/profusion_pr — 昇腾 NPU 推理适配

模型:siyan824/profusion_pr(PROFusion,ICRA 2026)—— 相机跟踪 + 稠密重建 系统的 位姿回归模块。 本文档给出在 昇腾 Ascend910 NPU 上运行该模型的完整方案(torch_npu 原生推理 + OpenAI 风格 HTTP 服务)。

1. 模型简介

PROFusion 面向 RGB-D 相机在剧烈运动 / 大视角变化等不稳定运动下仍然鲁棒地重建场景。本仓库为其 pose regression module 权重:

  • 输入:连续两帧 RGB-D(参考帧 ref + 源帧 src,各含 RGB 图、深度图、相机内参)
  • 输出:src 帧相对 ref 帧的 4x4 相机位姿矩阵(旋转 + 平移,metric 米尺度)
  • 用途:RGB-D SLAM / AR / 机器人实时跟踪与稠密重建的位姿初值
项值
架构PROFusion(DUSt3R / SLAM3R 系多视图视觉 Transformer)
组件PatchEmbed(16x16) + 24×编码器(ViT Block, RoPE100) + 12×多视图双向解码器 + PoseHead
参数量约 0.54B(fp32 权重约 2.16 GB)
上游官方代码 https://github.com/siyandong/PROFusion ;权重 https://huggingface.co/siyan824/profusion_pr
许可证CC BY-NC-SA 4.0(非商用)

为什么不用 vLLM-Ascend?

PROFusion 不是自回归语言模型:无语 tokenizer、无 token 序列自回归解码,输出是 4×4 位姿矩阵而非 token。vLLM/vLLM-Ascend 的注册表并不包含此类多视图位姿回归架构,因此本仓库采用 torch_npu 原生前向推理 + FastAPI 服务化的路线。

2. 环境依赖

软件版本
昇腾驱动Ascend910(CANN 8.x)
Python3.11
torch + torch_npu2.9.0 + 2.9.0.post1
numpy>=1.26
opencv-python4.x(可选,解码图像用)
fastapi / uvicorn服务化需要
safetensors读 model.safetensors

安装:

source /usr/local/Ascend/ascend-toolkit/set_env.sh   # 昇腾 CANN 环境
pip install torch==2.9.0 torch_npu==2.9.0.post1 \
    numpy opencv-python safetensors fastapi uvicorn tqdm

本仓库已本地化官方 pose_regression/ 包(CC BY-NC-SA 4.0),仅两处 NPU 兼容改动:MyNvtxRange(原 torch.cuda.nvtx)改为 no-op;位姿头 SVD 正交化移至 CPU。图像/深度前处理不依赖 PIL。

3. 目录结构

profusion_pr/
├── inference.py              # NPU 推理脚本(必选)
├── server.py                 # OpenAI 风格 HTTP 服务(可选)
├── README.md                 # 本文档
├── requirements.txt          # 依赖清单
├── pose_regression/          # 官方源码本地化(CC BY-NC-SA 4.0)
└── assets/                   # 截图素材
    ├── agent_workflow.png
    ├── npu_device_call.png
    └── model_result.png

4. 权重准备

将权重大文件放到 weights/model/(profusion_pr.pth 或 model.safetensors 任一个即可,未入库):

mkdir -p weights/model
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download siyan824/profusion_pr --local-dir weights/model

5. 推理

5.1 一行跑通(内置合成 RGB-D 帧对)

python inference.py --model_path ./weights/model --device npu:0

实测输出(Ascend910,npu:0,missing=0 unexpected=0):

{
  "model": "siyan824/profusion_pr",
  "device": "npu:0",
  "pose_4x4": [
    [0.99999201, 0.00233500, -0.00332200,  0.016577],
    [-0.00237900, 0.999906, -0.01345900,  0.026829],
    [0.00329000, 0.013468,  0.999904,   -0.313682],
    [0, 0, 0, 1]
  ],
  "translation_m": [0.016577, 0.026823, -0.313682],
  "rotation": [ ... ]
}

5.2 自定义 RGB-D 帧对

views.json(第 1 帧 = ref、第 2 帧 = src;image/depth 可为文件路径或内联数组):

{"views": [
  {"image": "ref.png", "depth": "ref_depth.png",
   "intrinsics": [[640,0,320],[0,640,240],[0,0,1]]},
  {"image": "src.png", "depth": "src_depth.png",
   "intrinsics": [[640,0,320],[0,640,240],[0,0,1]]}
]}
python inference.py --model_path ./weights/model --input_file views.json --device npu:0

6. 服务化推理(OpenAI 风格)

启动服务(启动即加载模型到 NPU,首个请求无冷启动):

python server.py --model_path ./weights/model --device npu:0 --port 8100

模型信息 / 健康检查:

curl http://127.0.0.1:8100/v1/models

两帧位姿估计(OpenAI chat/completions 接口):

curl -s http://127.0.0.1:8100/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "siyan824/profusion_pr",
  "messages": [{"role":"user","content":{
    "type":"rgbd_views",
    "frames": [
      {"image_uri":"/path/ref.png","depth_uri":"/path/ref_d.png",
       "intrinsics":[[640,0,320],[0,640,240],[0,0,1]]},
      {"image_uri":"/path/src.png","depth_uri":"/path/src_d.png",
       "intrinsics":[[640,0,320],[0,640,240],[0,0,1]]}
    ]}}]
}'

返回 choices[0].message.content 为 JSON(含 pose_4x4 / translation_m / rotation)。

7. 注意事项 / 适配记录

项说明
输入分辨率内部用 224x224(patch=16 的整数倍),自定义输入自动缩放即可
SVD位姿头 9D→SO(3) 的 torch.svd 在昇腾存在算子编译问题,改在 CPU 执行(3x3 极小矩阵,不影响性能)
RoPE官方 cuRoPE2D(CUDA kernel)不可用,自动走纯 PyTorch 慢版(缓存 cos/sin 表)
显存fp32 权重约 2.2 GiB + 激活,Ascend910 单卡轻松运行
深度单位米(metric 尺度);若其他单位请先归一

8. 验收截图

(assets/ 下三个截图,由使用者自取):

  • agent_workflow.png:Agent 适配工作流
  • npu_device_call.png:NPU 设备调用日志
  • model_result.png:模型最终推理结果截图

9. 原始参考

  • 论文:PROFusion(ICRA 2026)
  • 官方代码:https://github.com/siyandong/PROFusion
  • 原权重:https://huggingface.co/siyan824/profusion_pr