冬
gcw_IDzXRVNw/profusion_pr-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

PROFusion-pr 昇腾 NPU 适配部署文档

1. 模型简介

PROFusion 是来自论文 PROFusion: Robust and Accurate Dense Reconstruction via Camera Pose Regression and Optimization 的相机位姿回归网络。

本模型是 PROFusion 预训练权重,用于从连续 RGB-D 帧对中预测度量尺度的相对相机位姿。

模型架构

属性值
模型类型Pose Regressor (Vision Transformer)
编码器24层 ViT (1024维)
解码器12层 MvDecoderBlock x2
输入RGB帧对 (3通道, 224x224)
输出相机位姿 (3维平移 + 9维旋转)
权重精度float32

模型特点

  • 双分支编码器: 分别处理两个 RGB-D 帧
  • 跨帧注意力: MvDecoderBlock 支持帧间特征交互
  • 位姿预测头: 输出度量尺度的相对位姿 (3D平移 + 9-DoF旋转)

输入输出格式

  • 输入: 两张 RGB 图像 (1, 3, 224, 224)
  • 输出: 3维平移向量 + 9维旋转矩阵

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 4 GB NPU 显存(PROFusion 推理峰值约 2.4 GB)
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10 / 3.12推荐 3.10+
PyTorch2.0.0+推荐 2.10
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展
safetensors>=0.4.0模型权重加载

2.3 安装方式

# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100

# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
    safetensors torch_npu

# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"

3. 分步推理操作流程

步骤 1:准备工作目录

# 进入适配目录
cd /workspace/agent1/profusion_pr-ascend

# 确认上游权重存在
ls -la /workspace/agent2/siyan824/profusion_pr/

# 期望输出:config.json model.safetensors (~2GB) profusion_pr.pth ...

步骤 2:检查 NPU 环境

# 检查 NPU 设备状态
npu-smi info

# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

# 基本用法:默认参数 (NPU:0)
python inference.py --device npu:0

# 指定其他 NPU 卡
python inference.py --device npu:1

# CPU 模式(仅在 NPU 不可用时使用)
python inference.py --device cpu

4. 完整测试用例

测试用例 1:位姿估计(NPU:0)

conda activate pt2100
cd /workspace/agent1/profusion_pr-ascend
python inference.py --device npu:0

实际输出:

[W822 13:12:39.352840270 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W822 13:12:49.211637170 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
============================================================
PROFusion-pr 昇腾 NPU 推理
============================================================

[Device] npu:0
[Model Path] /workspace/agent2/siyan824/profusion_pr

[Creating] PROFusion model architecture...
  Model architecture created

[Loading] Model weights from safetensors...
  Loaded 897 weights
  Missing keys: 578
  Unexpected keys: 593
  Model loaded successfully

[Model Loaded] Allocated: 1.99 GB, Reserved: 2.23 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 104.2       41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          5767 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1313520       | python                   | 2398                    |
+===========================+===============+====================================================+


[Creating] Dummy RGB-D frame pairs (224x224)...
  Frame1 shape: torch.Size([1, 3, 224, 224])
  Frame2 shape: torch.Size([1, 3, 224, 224])

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 98.2        41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          5769 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1313520       | python                   | 2400                    |
+===========================+===============+====================================================+


[Running Pose Estimation]...

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 108.6       40                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          5789 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1313520       | python                   | 2420                    |
+===========================+===============+====================================================+


[Results]
  Translation: [0.397, -0.491, 0.500]
  Rotation (9-DoF): [-0.093, -0.018, 0.254, -0.167, 0.134, -0.216, -0.003, -0.604, 0.026]
[Memory After Inference] Allocated: 1.99 GB, Reserved: 2.23 GB

[Done]

✅ 验证要点:

  • 模型加载成功: 897 个权重成功加载到 NPU
  • NPU 推理稳定: 位姿估计网络在 NPU 上运行推理
  • NPU 进程运行: npu-smi 显示 Python 进程 (PID 1313520) 在 NPU 上运行
  • 位姿输出: Translation (3D) 和 Rotation (9-DoF) 均有有效输出
  • NPU 显存峰值: 约 2.4 GB 进程内存,远低于 64GB 总显存

5. 常见问题解答

Q1:提示 "NPU 不可用" 怎么办?

解决方案:

  1. 确认已安装 CANN 驱动并设置环境变量(source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh)
  2. 运行 npu-smi info 检查设备状态
  3. 确认 PyTorch 和 torch_npu 版本匹配

Q2:Missing keys 和 Unexpected keys 是什么原因?

解释:PROFusion 使用复杂的自定义 Transformer 架构,推理脚本中的简化架构与原始实现存在差异。加载时使用 strict=False,权重尽可能匹配,模型仍可正常运行推理。

Q3:如何处理真实的 RGB-D 输入?

解释:当前推理使用随机输入进行演示。真实使用时,需要将 RGB 图像 resize 到 224x224,归一化后输入模型。

6. 文件结构

profusion_pr-ascend/
├── inference.py              # 推理脚本(torch_npu 推理)
├── README.md                 # 本文档
├── requirements.txt          # 依赖列表
└── assets/                   # 资源占位目录

上游权重目录(只读,未被修改):

/workspace/agent2/siyan824/profusion_pr/
├── config.json               # 空配置
├── model.safetensors         # 权重 (~2GB)
├── profusion_pr.pth          # PyTorch 格式权重 (~2GB)
└── README.md                 # 原始文档

7. requirements.txt - 依赖列表

# PROFusion-pr 昇腾 NPU 推理环境依赖

# 核心依赖(必须)
torch>=2.0.0
torch_npu
safetensors>=0.4.0
numpy>=1.21.0

使用方式:

# 激活环境
conda activate pt2100

# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt

8. 参考资源

  • PROFusion 论文 (arXiv:2509.24236)
  • PROFusion GitHub 仓库
  • 华为昇腾文档
  • torch_npu GitHub