#NPU
原始模型: depth-anything/DA3METRIC-LARGE — Depth Anything 3 Metric Large,单目度量深度估计,理想于真实尺度恢复。模型卡显示 0.35B 参数(实际 334M),Apache-2.0 许可。
vitl, dim_in=1024, out_layers [4,11,17,23]) + DPT Head (features 256, out_channels [256,512,1024,1024], output_dim=1)。配置文件位于 src/depth_anything_3/configs/da3metric-large.yaml,权重 model.safetensors 1.25 GiB。(1, H, W) 度量深度、sky 置信度及相机参数。InputProcessor 以 upper_bound_resize 将短边缩放至 process_res=504 并 ImageNet 归一化。Prediction.depth 形状 (N, H, W) float32,conf、extrinsics/intrinsics 在单视图下为 None(多视图时输出姿态)。DepthAnything3.forward 内部的 torch.autocast(在当前 CPU/NPU 环境下 autocast(cpu, bfloat16) 会 hanging,禁用后 CPU 25s / NPU 63ms 且精度一致),并对 depth_anything_3.utils.export 中可选依赖 (moviepy, pycolmap, trimesh, gsplat) 做 try 容错,保证纯推理链路不依赖重型可视化库。本仓库: 昇腾 Ascend910B 单卡 npu:0 真实推理适配,权重通过 huggingface_hub 从本地缓存加载,不重新下载。
npu:0 (npu-smi 25.5.5)4010e39f3634a45bc60553321fb49fb760bd594e, weight 1.3GB safetensorstorch.npu.is_available()==True, torch.npu.get_device_name(0)=="Ascend910_9362", npu-smi info 可用pip install -r requirements.txt
# 需已安装 CANN 8.5.1 且 torch_npu 与 torch 版本匹配
# 额外依赖 evo/mpl/trimesh 仅用于可选导出,纯推理可不装但已列入 requirements 保证 import 容错权重通过 DepthAnything3.from_pretrained("depth-anything/DA3METRIC-LARGE") 自动从 HF 镜像 (HF_ENDPOINT=https://hf-mirror.com) 缓存加载,首次运行约 17s 加载 334M 参数。
默认命令(单张 504x504 梯度+噪声确定性图像)在 npu:0 上执行:
python inference.py验证一致性与性能:
python inference.py --mode validate # CPU vs NPU + benchmark
python inference.py --mode benchmark # 仅性能固定输入: seed=42 合成图像 504x504(梯度背景 + 中央方块,PIL),process_res=504。
默认 NPU 推理 (python inference.py on npu:0, FP32, 无 autocast):
[OUTPUT] depth shape: (1, 504, 504) dtype: float32
[OUTPUT] depth min: 1.290164
[OUTPUT] depth max: 1.545251
[OUTPUT] depth mean: 1.519255
[OUTPUT] depth std: 0.031102
[OUTPUT] conf shape: None
[OUTPUT] extrinsics shape: None
[OUTPUT] intrinsics shape: None
[OUTPUT] latency: 367.42 ms (首轮含编译) / 稳定 63ms
[OUTPUT] finite: True
[DEVICE] first_param device: npu:0
[RESULT] PASS多视图输入时会输出相机外参/内参,单视图时为 None 属预期行为。
使用完全相同权重、同一张 504x504 图像、同一预处理、eval 模式、FP32、seed=42。
atol=0.2, rtol=0.05(度量深度量纲 ~1.5,NPU 卷积/注意力内核微小数值漂移,mean 误差仅 0.3%)allclose=True, finite=True, shape (1,504,504)一致 → PASS一致性证据保存为 /tmp/da3_cpu_depth.npy 与 /tmp/da3_npu_depth.npy,可通过 scripts/compare_outputs.py 复验。
判定为 smoke consistency(单样本固定输入),未在完整 NYU-Depth v2 / KITTI 数据集上做全量精度评测。
torch.npu.synchronize() 包裹计时,3 次 warmup + 10 次测量,batch=1, res=504x504, dtype=FP32, device=npu:0。
含预处理 (InputProcessor) 0.004s,不含模型下载与权重加载。
三张证据图由 scripts/render_xterm_evidence.mjs --style raw 从本次真实日志渲染,深灰背景、xterm.js 等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$:
assets/agent_workflow.png — 下载、侦察、加载、NPU 推理、一致性、benchmark 完整流程assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、device_name、参数 device、输入/输出 deviceassets/model_result.png — python inference.py 真实输出、depth 统计、耗时、PASS/FAILREADME 仅引用图片,不重复渲算工具细节。

torch.autocast 后以 FP32 运行,未启用 BF16/FP16 自动混合精度;如需更高吞吐可尝试 NPU BF16 但需另行验证。gsplat / moviepy / pycolmap / open3d 未安装,glb/gs_video/colmap 导出不可用,纯 mini_npz/npz/depth_vis 可用。extrinsics=None),多视图需提供 extrinsics/intrinsics。Hardware: NPU NPU Ascend Ascend910 depth-estimation metric-depth vision-transformer DA3