wrhhh/depth-anything-DA3METRIC-LARGE-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

depth-anything/DA3METRIC-LARGE on Ascend NPU

1. 模型简介

DA3 Metric Large 是 ByteDance Seed Team 发布的 Depth Anything 3 系列中的度量深度模型,基于 DINOv2 ViT-L (1024 dim, 24 layers) + DPT head,参数量 0.35B,专用于单目度量深度估计,支持同步输出深度、置信度、天空分割、相机外参/内参及 3D 点云。模型权重托管于 depth-anything/DA3METRIC-LARGE (model.safetensors 1.3GB),官方实现为 depth-anything-3 (Apache-2.0),pipeline_tag depth-estimation。

  • 官方仓库: https://github.com/ByteDance-Seed/depth-anything-3
  • HuggingFace: https://huggingface.co/depth-anything/DA3METRIC-LARGE
  • 架构: DepthAnything3Net (net: DINOv2 vitl out_layers [4,11,17,23], head: DPT dim_in 1024 features 256)
  • 输入: 单张 RGB 图像 (H×W×3),经上界 resize 到 longest side 504 + 最近 14 倍数对齐,归一化后为 (1,1,3,H,W)
  • 输出: depth (1,1,H,W) float32 米制深度, sky (1,1,H,W) 天空置信, aux 辅助字典

本仓已在单卡 Ascend910B (npu:0) 上完成真实权重加载与推理验证,兼容 CPU 回退。

2. 验证环境

  • NPU: Ascend910_9362 (910B) x2, 显存 64GB, 驱动 npu-smi 25.5.5
  • CANN: 8.5.1
  • Torch: 2.9.0+cpu + torch_npu 2.9.0.post1
  • Python: 3.11.14 (aarch64)
  • 验证时间: 2026-08-21 18:30 CST
  • 本地权重: working/models/depth-anything-DA3METRIC-LARGE (model.safetensors 1336734448 bytes, 1.245 GiB)

检测命令:

npu-smi info
python -c "import torch; import torch_npu; print(torch.npu.is_available()); print(torch.npu.get_device_name(0))"

3. 安装依赖

pip install -r requirements.txt
# 额外源码 (已内置于推理脚本的 mock 兼容)
git clone https://github.com/ByteDance-Seed/depth-anything-3 /tmp/da3
export PYTHONPATH=/tmp/da3/src:$PYTHONPATH

关键依赖: torch, torch_npu, torchvision, numpy<2, pillow, opencv-python, einops, omegaconf, addict, safetensors, huggingface_hub

4. NPU 推理

4.1 默认一键推理

python inference.py
  • 自动探测 npu:0,若不可用回退 CPU
  • 加载本地权重 (优先 working/models/depth-anything-DA3METRIC-LARGE),打印模型、设备、输入、深度统计、耗时、PASS/FAIL
  • 额外执行 CPU-NPU 一致性校验

4.2 专项模式

python inference.py --mode validate   # 仅一致性校验 + 推理
python inference.py --mode benchmark  # 性能压测

4.3 预期输入输出契约

  • 输入: PIL.Image 或 np.ndarray H×W×3 uint8,process_res=504,upper_bound_resize + 14 对齐
  • 输出: depth shape (1,1,504,504) float32,值域约 0.60.72 (随机输入),真实图像约 0.120 米
  • 设备: NPU:0,dtype fp16 autocast,输入 tensor fp32 归一化

5. 真实推理结果

5.1 NPU 默认推理 (npu:0, fp16, 504x504 dummy seed=42)

[INFO] model_name: depth-anything/DA3METRIC-LARGE
[INFO] local_model_dir: /opt/atomgit/adapt-npu-agent/working/models/depth-anything-DA3METRIC-LARGE
[INFO] loading_backend: DepthAnything3 (custom da3)
[INFO] device: npu:0, dtype: torch.float16
[INFO] task: depth-estimation (metric depth)
[INFO] architecture: DINOv2 ViT-L + DPT head
[INFO] model loaded in 3.52s
[INFO] param_device: npu:0
[INFO] input: dummy PIL image 504x504x3, seed=42, process_res=504
[INFO] input_tensor shape: (1, 1, 3, 504, 504) dtype torch.float32
[RESULT] depth shape: (1, 1, 504, 504)
[RESULT] depth dtype: torch.float32 device: npu:0
[RESULT] depth stats: min 0.642681 max 0.719793 mean 0.690193 std 0.015691
[RESULT] sky shape: (1, 1, 504, 504) stats min 0.000000 max 0.306783 mean 0.000152
[PERF] inference latency (ms): avg 29.58 min 29.49 max 29.68 p50 29.57 p90 29.66 p95 29.67
[PERF] throughput: 33.80 images/s (batch 1)
[INFO] PASS: NPU inference completed successfully

5.2 CPU-NPU 一致性 (同输入 seed=123, 504x504)

[VALIDATE] CPU-NPU consistency check
[VALIDATE] diff max 0.002084 mean 0.001269
[VALIDATE] PASS: CPU-NPU consistency within tolerance
  • 阈值: mean <0.01, max <0.02 判定 PASS
  • 类型: 单样本 smoke consistency (非完整数据集评测),用于证明 NPU 计算正确性

6. CPU-NPU 一致性验证

  • 方法: 同一随机输入 (seed=123) 分别在 CPU (fp32) 与 NPU (fp16 autocast + fp32 输出) 上执行 model.model(tensor),比较 depth 的逐像素绝对误差
  • 结果: mean 0.00127, max 0.00208 (<0.01),表明 NPU 精度与 CPU 高度一致
  • 设备: torch.npu.is_available()=True, device_name=Ascend910_9362, torch_npu_version=2.9.0.post1

7. 性能测试

所有计时在 torch.npu.synchronize() 前后测量,预热 3 次,正式 10 次,batch size 1,process_res 504,dtype fp16:

  • 平均延迟: 29.58 ms
  • 最小/最大: 29.49 / 29.68 ms
  • p50/p90/p95: 29.57 / 29.66 / 29.67 ms
  • 吞吐: 33.8 images/s
  • 峰值显存: 空闲 57.37 GiB / 总计 61.27 GiB (单卡)
  • 模型加载: 3.5s (含权重 1.3GB 从本地盘读取)
  • 备注: 含预处理 (InputProcessor) 不计入纯模型延迟;纯 model.model 延迟即上述数值,若含 inference.py 全流程约 30-35ms

测试命令:

python inference.py --mode benchmark

8. 自验证截图

  • assets/agent_workflow.png: 阶段日志 (下载、侦察、加载、NPU 推理、验证、性能)
  • assets/npu_device_call.png: npu-smi info + torch.npu.is_available() + 设备名
  • assets/model_result.png: python inference.py 真实终端输出

9. 已知限制

  • 需本地权重目录 working/models/depth-anything-DA3METRIC-LARGE (1.3GB),离线环境无法自动下载
  • 依赖 depth-anything-3 源码 (/tmp/da3/src) 已通过 PYTHONPATH 注入,未打包进仓;若 clean 环境需手动 git clone
  • 可选依赖 plyfile, trimesh, moviepy, open3d, evo, e3nn, gsplat, pycolmap 已在推理脚本中 mock,仅保留核心深度推理,3D 高斯导出 (export_format=glb/gs_ply) 不可用
  • scipy 未安装时姿态插值警告但不影响单图深度
  • NPU 需 fp16 autocast,CPU 为 fp32/bf16,存在约 1e-3 量级误差,属正常精度
  • 输入 process_res 固定 504 (14 倍数),多图 batch 会中心裁剪到最小尺寸
  • 未执行完整 NYU-Depth v2 / KITTI 数据集评测,仅单样本一致性

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910