atlasleong/pi3-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Pi3(yyfz233/Pi3)· 昇腾 NPU 图像转 3D(image-to-3d)交付

本目录是 yyfz233/Pi3(Permutation-Equivariant Visual Geometry Learning,π³)在昇腾 Ascend 910B4 上使用 torch_npu 的离线 image-to-3d(多视图→点云重建)适配与交付文档。 所有推理结果均为真实运行结果,日志与结构化证据见 logs/;模型权重全程使用本地文件,不联网、不重新下载。 目标设备:npu:7。


1. 模型简介

yyfz233/Pi3(π³)是一个前馈(feed-forward)视觉几何重建模型:给定同一物体的多张 RGB 视角图,一次性重建出对应的 3D 点云(local points + 全局点),并同时估计每张图的相机位姿(camera poses)。与需要逐物体优化的方法不同,Pi3 直接前向输出几何,适合快速、可泛化的 image-to-3d 重建。

  • 论文:Pi³: Permutation-Equivariant Visual Geometry Learning(arXiv:2507.13347);
  • 编码器:DINOv2-Large(ViT-L/14,patch_size=14);
  • 解码器:36 层、dec_embed_dim=1024、16 头、RoPE 位置编码(pos_type=rope100);
  • 头:点解码器(LinearPts3d,输出 local_points 与全局 points)、置信度头(conf)、相机位姿头(CameraHead,输出 (B, N, 4, 4) 变换矩阵);
  • 参数量:958,696,732(约 0.96B);
  • 权重文件:model.safetensors(3,834,909,248 bytes ≈ 3.57 GiB);
  • 源码许可证:BSD-3-Clause(pi3-code/LICENSE)。

任务定义(image-to-3d):输入 (B, N, 3, H, W) 的多视角图像张量,输出字典包含:

输出键形状含义
points(B, N, H, W, 3)全局点云坐标(经相机位姿反投影)
local_points(B, N, H, W, 3)局部点坐标(以每个相机为参考系)
conf(B, N, H, W, 1)每像素置信度(未激活)
camera_poses(B, N, 4, 4)每视角相机位姿(旋转块行列式为 1)

2. 模型源与固定版本(可复现性)

项值
源仓库(HuggingFace)https://huggingface.co/yyfz233/Pi3
固定 revision(HF commit)ae722e7039287d0c8fde9f11f197f804f44b510c
源码仓库(GitHub)yyfz233/Pi3
固定代码 revision9fa3ddb3f8d53041f8b2738df404f62223bbaa7b
本地模型目录/work/pipeline/models/cv9/pi3
本地代码目录/work/pipeline/models/cv9/pi3-code
本地权重文件model.safetensors
权重大小3,834,909,248 bytes(≈ 3.57 GiB)
权重 SHA25633580e4702ac671558aedeab1148fd08118f7ce45bdbeb99f3e3cf340062875d
模型配置{"decoder_size": "large", "pos_type": "rope100"}

2.1 本地模型文件清单

config.json              54 bytes
model.safetensors   3,834,909,248 bytes

权重 SHA256 在每次推理时由 inference.py 重新计算并写入 logs/npu_result.json,确保可追溯。


3. 环境依赖清单

3.1 硬件 / 软件环境

项值
NPUAscend 910B4-1(单卡,共 8 卡可见)
目标设备npu:7
驱动 / npu-smi25.5.1
CANN8.5.1
Python3.11.14
操作系统openEuler 22.03 (SP4) aarch64

3.2 Python 依赖

基础镜像已预装(禁止重装/替换,否则破坏 torch↔torch_npu 匹配对):

包版本
torch2.9.0+cpu
torch_npu2.9.0
huggingface_hub0.36.0(基础镜像 system-site-packages,模型代码 PyTorchModelHubMixin 需要)

requirements.txt 固定版本(非 torch 依赖,用阿里云镜像安装):

safetensors==0.8.0
plyfile==1.1.5
numpy==1.26.4
Pillow==12.3.0

安装命令:

export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
export PIP_TRUSTED_HOST=mirrors.aliyun.com
source /usr/local/Ascend/ascend-toolkit/set_env.sh   # 或使用已生效的 CANN 环境
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

复用现有 per-model venv:/work/pipeline/runtime/venvs-cv9/pi3-npu。


4. 测试输入(CC0,可再分发)

测试输入为 inference.py 内置的自生成 CC0 合成多视角图像(不下载任何受版权保护的数据):

  • 生成方式:NumPy + Pillow 正交投影渲染一个倾斜 3D 立方体的 3 个视角(不同方位角);
  • 尺寸:224 × 224 RGB,views=3,归一化到 [0,1];
  • 确定性:固定 seed=42;
  • 来源:self-authored synthetic multi-view cube rendered locally with NumPy + Pillow;
  • 许可证:CC0-1.0。

5. 推理操作流程

5.1 一键运行

cd /work/pipeline/jobs/cv9/pi3/pi3-npu
source /usr/local/Ascend/ascend-toolkit/set_env.sh

OMP_NUM_THREADS=16 MKL_NUM_THREADS=16 \
  /work/pipeline/runtime/venvs-cv9/pi3-npu/bin/python inference.py \
    --device npu:7 --views 3 --size 224 --seed 42 \
    --save-dir output

参数说明:

参数默认说明
--model-path/work/pipeline/models/cv9/pi3含 config.json + model.safetensors 的目录
--code-path/work/pipeline/models/cv9/pi3-code固定 revision 的 Pi3 源码根目录
--devicenpu:7目标 NPU 设备
--views3合成视角数
--size224图像高/宽(14 的倍数)
--seed42确定性随机种子
--conf-threshold0.1置信度过滤阈值(过低时自动回退 top-K 点)
--save-diroutput/产物输出目录

5.2 产物

  • output/input_views.png — 3 个合成视角的拼接图;
  • output/points.ply — 重建点云(ASCII PLY);
  • output/result_stats.json — 输出数值摘要;
  • logs/npu_result.json — 结构化 NPU 推理结果(交付验收用)。

5.3 行为保证(fail-closed)

  • 无静默 CPU 回退:NPU 初始化、设备放置或执行失败时以非零退出;
  • 每个输入张量、模型、输出张量在推理前后均断言位于 npu:7;
  • 日志记录硬件名、CANN、torch/torch_npu 版本、输出形状、数值统计、耗时与退出码。

6. 完整测试用例(真实输出)

6.1 运行命令

cd /work/pipeline/jobs/cv9/pi3/pi3-npu
OMP_NUM_THREADS=16 MKL_NUM_THREADS=16 \
  /work/pipeline/runtime/venvs-cv9/pi3-npu/bin/python inference.py \
    --device npu:7 --views 3 --size 224 --seed 42 --save-dir output

6.2 输出结果(最终真实运行日志,2026-08-20 09:29:31)

------------------------------------------------------------------------------
[2026-08-20 09:28:55] Pi3 NPU inference (image-to-3d)
------------------------------------------------------------------------------
[2026-08-20 09:28:55] python:        3.11.14 (/work/pipeline/runtime/venvs-cv9/pi3-npu/bin/python)
[2026-08-20 09:28:57] torch:         2.9.0+cpu
[2026-08-20 09:28:57] torch_npu:     2.9.0
[2026-08-20 09:28:57] CANN:          8.5.1
[2026-08-20 09:28:57] NPU name:      Ascend910B4-1
[2026-08-20 09:28:57] NPU device:    npu:7 (current=7)
[2026-08-20 09:28:57] NPU count:     8
[2026-08-20 09:28:57] model config:  decoder_size=large pos_type=rope100
[2026-08-20 09:28:35] weight bytes:  3834909248
[2026-08-20 09:28:35] weight sha256: 33580e4702ac671558aedeab1148fd08118f7ce45bdbeb99f3e3cf340062875d
[2026-08-20 09:28:35] state_dict:    missing=0 unexpected=0
[2026-08-20 09:29:26] running Pi3 forward pass on NPU (fp32)...
[2026-08-20 09:29:26]   out[points]:        shape=(1, 3, 224, 224, 3) device=npu:7 dtype=torch.float32
[2026-08-20 09:29:26]   out[local_points]:  shape=(1, 3, 224, 224, 3) device=npu:7 dtype=torch.float32
[2026-08-20 09:29:26]   out[conf]:          shape=(1, 3, 224, 224, 1) device=npu:7 dtype=torch.float32
[2026-08-20 09:29:26]   out[camera_poses]:  shape=(1, 3, 4, 4)        device=npu:7 dtype=torch.float32
------------------------------------------------------------------------------
[2026-08-20 09:29:26] output statistics:
[2026-08-20 09:29:26]   points:  shape=(1, 3, 224, 224, 3) min=-0.2407 max=0.4325 mean=0.1181 std=0.1465
[2026-08-20 09:29:26]   conf(sigmoid): min=0.0002 max=0.5500 mean=0.1319
[2026-08-20 09:29:26]   camera_poses: shape=(1, 3, 4, 4) det_mean=1.0000 (rotation block)
[2026-08-20 09:29:26]   points finite fraction: 1.000000000 (non-finite=0)
[2026-08-20 09:29:26]   conf mask kept: 71516/150528 pixels (47.51%)
[2026-08-20 09:29:26]   export points: 71516
[2026-08-20 09:29:31] total wall:    41.737s
[2026-08-20 09:29:31] Pi3 NPU inference completed successfully.
EXIT_CODE=0

6.3 结果摘要

指标值
exit_code0(成功)
npu_availabletrue
enginetorch_npu
input_device / model_device / output_devicenpu:7 / npu:7 / npu:7
输出形状points=(1,3,224,224,3)、conf=(1,3,224,224,1)、camera_poses=(1,3,4,4)
points 范围[-0.2407, 0.4325],mean=0.1181,std=0.1465
conf(sigmoid)min=0.0002,max=0.5500,mean=0.1319
相机位姿旋转块行列式均值0.99999988 ≈ 1.0(有效旋转矩阵)
points 有限值比例1.000000000(非有限值 0)
导出点云点数71,516
前向耗时 / 总耗时5.92 s / 41.74 s

完整结构化结果见 logs/npu_result.json。所有 points/local_points/conf/camera_poses 输出均位于 npu:7,无 CPU 回退。


7. NPU 证据

  • 并发 npu-smi info 监控记录见 logs/npu_device_call.log(全量)与 logs/npu_device_call_active.log(聚焦窗口);
  • 推理期间 NPU 7 上活动进程:PID 518609(python),设备内存从 114 MB 增长到 4652 MB;
  • logs/npu_result.json 中的 placements 字段逐项记录 input/model/output 均位于 npu:7。

8. 交付文件清单

inference.py
requirements.txt
readme.md / README.md
render_screenshots.py
.gitignore
assets/agent_workflow.png
assets/npu_device_call.png
assets/model_result.png
logs/npu_inference_raw.log
logs/npu_inference.log
logs/npu_device_call.log
logs/npu_device_call_active.log
logs/npu_result.json
logs/modelagent_transcript.log
logs/modelagent_workflow.log
output/input_views.png
output/points.ply
output/result_stats.json
SHA256SUMS

9. 备注

  • 环境为共享宿主,偶发 CANN 初始化/线程创建瞬时失败(aclInit 500000、libgomp),最终运行通过重试成功;已记录于 logs/npu_inference.log。
  • 未改动容器内 torch/torch_npu,全部非 torch 依赖使用阿里云 PyPI 镜像并固定版本。
  • 推理使用 fp32;torch.linalg.det(用于验证相机旋转块)在 NPU 上自动回退 CPU 计算,不影响主推理路径。
  • 本交付为离线、本地权重推理,不联网、不下载、不包含任何凭据。

ModelAgent 现场会话界面

下图是本次适配与第二轮上游规范复核的 ModelAgent 流式会话只读回放,来源为公开交付中的脱敏会话日志;命令、问题定位、修复和验收结论均来自真实会话。

ModelAgent 现场会话界面

昇腾 NPU 适配证据截图

Agent 完整适配工作流

Agent 完整适配工作流

NPU 硬件设备调用日志

NPU 硬件设备调用日志

模型最终适配验收结果

模型最终适配验收结果