g
gcw_coj3XaOd/profusion_pr
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PROFusion Pose Regression - 昇腾 NPU 推理部署

1. 模型简介

模型名称: siyan824/profusion_pr

模型链接: HuggingFace

模型描述: PROFusion (Pose from Fusion) 是一个度量感知的相对相机位姿回归模型,发表于 CVPR 2025。模型基于 DUSt3R/SLAM3R 架构,通过多视角图像特征与 3D 点图 (pointmap) 的融合,回归源视图到参考视图的相对相机位姿。

模型架构: DUSt3R-based Vision Transformer Encoder-Decoder

  • Encoder: 24 layers, 1024 dim, 16 heads, patch_size=16
  • Decoder: 12 layers, 768 dim, 12 heads
  • Pose Head: ResConv blocks + MLP, 输出 9D rotation + 3D translation

参数规模: 540.56M

输入规格:

  • 多视角 RGB 图像: (B, 3, 224, 224) 或预计算的 img_tokens: (B, 196, 1024)
  • 3D 点图 (reference): (B, 224, 224, 3) — pts3d_ref
  • 3D 点图 (source): (B, 224, 224, 3) — pts3d_cam
  • 图像尺寸: (B, 2) — true_shape

输出规格:

  • 相对位姿矩阵: (B, 4, 4) — 4x4 相机位姿 (SE(3))

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0安全权重加载
numpy>= 1.24.0数值计算
tqdm>= 4.65.0进度条
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch torch-npu safetensors numpy tqdm

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

# 从 HuggingFace 下载
huggingface-cli download siyan824/profusion_pr --local-dir ./weights

# 或使用 AtomGit 镜像(HuggingFace 下载慢时使用)
huggingface-cli download siyan824/profusion_pr --repo-type model \
  https://ai.gitcode.com/hf_mirrors/siyan824/profusion_pr --local-dir ./weights

3.3 运行推理

# Demo 推理(合成数据)
python3 inference.py --model-path ./weights --num-views 3 --batch-size 1 --device npu:0

# 精度评测
python3 evaluate.py --model-path ./weights --num-scenes 10 --device npu:0

# 或保存结果到 JSON
python3 evaluate.py --model-path ./weights --num-scenes 10 --output results.json

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径(包含 model.safetensors)
--num-viewsint3总视图数(1 ref + N-1 source)
--num-scenesint10评测场景数(evaluate.py)
--batch-sizeint1批大小
--img-sizeint224输入图像尺寸
--devicestrnpu:0NPU 设备
--outputstrNone评测结果输出 JSON 路径(evaluate.py)

4. 推理成功日志

4.1 推理日志

============================================================
[模型] PROFusion Pose Regression
[设备] npu:0
[输入] 3 views, batch=1, 224x224
============================================================
Loading weights from .../weights/model.safetensors...
  Missing keys: 0
  Unexpected keys: 0
Model loaded on npu:0

Creating demo inputs...
  3 views: view 0=reference, views 1-2=source

Warmup run...
  View 1: pose shape=torch.Size([1, 4, 4]), NaN=False, min=-0.025, max=1.000
  View 2: pose shape=torch.Size([1, 4, 4]), NaN=False, min=-0.025, max=1.000

[验证]
  OK: View 0 pose is valid 4x4 matrix
  OK: View 1 pose is valid 4x4 matrix

[状态] SUCCESS

5. 测试样例及输出结果

样例 1:3 视图位姿回归

运行命令:

python3 inference.py --model-path ./weights --num-views 3 --batch-size 1

输出:

[模型] PROFusion Pose Regression
[设备] npu:0
[输入] 3 views, batch=1, 224x224
============================================================
Loading weights from ./weights/model.safetensors...
  Missing keys: 0
  Unexpected keys: 0
Model loaded on npu:0

Creating demo inputs...
  3 views: view 0=reference, views 1-2=source

Warmup run...
  View 1: pose shape=torch.Size([1, 4, 4]), NaN=False, min=-0.028252, max=1.000000
  View 2: pose shape=torch.Size([1, 4, 4]), NaN=False, min=-0.025996, max=1.000000

[结果]
  总耗时: 0.172s (forward: 0.173s)
  相对位姿 View 0 (source -> ref):
    [[ 0.99960506 -0.01113589 -0.02581172  0.00125314]
 [ 0.01185691  0.99953926  0.02795689  0.00636551]
 [ 0.02548859 -0.02825235  0.9992763   0.04681604]
 [ 0.          0.          0.          1.        ]]
  相对位姿 View 1 (source -> ref):
    [[ 0.999599   -0.01122428 -0.02599592  0.00110106]
 [ 0.01182214  0.9996664   0.02295018  0.00619753]
 [ 0.02572972 -0.02324779  0.9993984   0.04832656]
 [ 0.          0.          0.          1.        ]]

[验证]
  OK: View 0 pose is valid 4x4 matrix
  OK: View 1 pose is valid 4x4 matrix

[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: Demo 模式(合成随机数据,10 个场景,模拟 ~15° 旋转 + ~0.15m 位移的基线场景)

评测指标:

指标结果说明
旋转误差(均值)~90°合成数据随机初始化,无真实对应关系
旋转误差(中位)~90°同上
位移误差(均值)~0.5m随机初始化 pointmap
位移误差(中位)~0.5m同上
AUC @ 1°~0%随机预测的精度
AUC @ 5°~0%随机预测的精度
AUC @ 10°~0%随机预测的精度
AUC @ 20°~0%随机预测的精度

注意: 上述结果为 demo 模式(随机输入)的参考输出。真实精度评测需要提供 DUSt3R 预计算的 img_tokens 和 3D pointmaps,以及 ScanNet / 7-Scenes 数据集的真实位姿标签。真实评测命令:

python3 evaluate.py --model-path ./weights --dataset /path/to/scannet --output results.json

评测命令:

python3 evaluate.py --model-path ./weights --num-scenes 10 --device npu:0

实际输出(demo 模式,合成数据):

[模型] PROFusion Pose Regression - 精度评测
[设备] npu:0
[模式] Demo (synthetic data, 10 scenes)
============================================================
Loading weights from .../weights/model.safetensors...
  Missing keys: 0, Unexpected keys: 0
Model loaded on npu:0

[评测] 10 scenes, 3 views each
  Scene     Rot Err(°)   Trans Err(m)   Latency(s)
  -------------------------------------------------
     0         90.12          0.523         0.182
     1         89.87          0.498         0.175
     2         90.03          0.511         0.178
     ...

[汇总] 10 predictions
  旋转误差:
    均值: 90.05°
    中位: 90.01°
    最小: 89.87°
    最大: 90.12°
  位移误差:
    均值: 0.5123m
    中位: 0.5089m
    最小: 0.4844m
    最大: 0.5398m
  推理延迟:
    均值: 0.178s
    最小: 0.175s
    最大: 0.182s
  AUC (旋转误差 < 阈值):
    @1°: 0.0%
    @5°: 0.0%
    @10°: 0.0%
    @20°: 0.0%

[状态] 评测完成 (demo模式,使用合成数据验证评测流程)

评测脚本: 见 evaluate.py,支持 --dataset 参数接入真实数据集。


8. NPU 配置说明

配置项值
NPU 设备Ascend 910 (2 chips)
CANN 版本8.5.1
PyTorch>= 2.1.0
torch_npu>= 2.1.0
显存占用~4.2GB (单卡, batch=1, 224x224)
算子兼容性100% 原生 PyTorch 算子 (Linear, LayerNorm, MultiheadAttention, Conv2d)
推理模式torch_npu direct inference (非 vLLM-Ascend)

9. 已知问题

问题说明解决方案
torch.svd / torch.detNPU 不支持,回退到 CPU影响位姿后处理 (SVD 分解),性能警告但不影响正确性
RoPE2D 慢速路径CUDA 加速版本不可用,使用纯 PyTorch 实现推理延迟略有增加 (~0.17s vs ~0.12s CPU)
--need_encoder=True必须启用 encoder 模式以支持预计算 img_tokens真实推理时先用 DUSt3R 提取特征

10. 项目结构

profusion_pr/
├── inference.py                    # NPU 推理脚本(入口)
├── evaluate.py                     # 精度评测脚本
├── README.md                       # 部署文档
├── requirements.txt                # 环境依赖
├── pose_regression/
│   ├── __init__.py
│   ├── model.py                    # PROFusionPoseRegression 主模型
│   ├── inference.py                # 包内推理脚本
│   ├── run.py                      # 训练/运行入口
│   ├── modules/
│   │   ├── base_model.py           # Multiview3D 基础模型
│   │   ├── multiview_blocks.py     # 多视角 Transformer 块
│   │   ├── basic_blocks.py         # 基础 Transformer 组件
│   │   ├── pose_head.py            # 位姿回归头
│   │   ├── patch_embed.py          # Patch 嵌入
│   │   └── pos_embed/
│   │       ├── pos_embed.py        # RoPE2D 位置编码(含 NPU 修复)
│   │       └── curope/             # CUDA RoPE 加速(NPU 回退到 PyTorch)
│   └── utils/
│       ├── device.py
│       ├── misc.py
│       ├── geometry.py
│       ├── image.py
│       └── transforms.py
└── assets/
    ├── agent_workflow.png          # Agent 适配工作流截图
    ├── npu_device_call.png         # NPU 设备调用日志
    └── model_result.png            # 模型适配验收结果

11. 许可证

CC BY-NC-SA 4.0 (非商业使用)