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

depth-anything/DA3METRIC-LARGE Ascend NPU 适配

#NPU

本仓库将 HuggingFace 上的 depth-anything/DA3METRIC-LARGE(DA3 Metric Large,ViT-L DINOv2 骨干 + DPT 解码头,0.35B 参数,monocular metric depth 统一深度-射线表征)适配为可在单卡昇腾 Ascend 910(npu:0)上真实运行的 GitCode AI model 仓库。支持 metric depth 与 sky 分割,输入任意 RGB 图像输出 metric 深度图。

  • 模型原始仓库:https://huggingface.co/depth-anything/DA3METRIC-LARGE
  • 权重:model.safetensors 1.27 GB(334,171,394 参数,406 tensors,float32),config.json 定义 da3metric-large(net vitl out_layers [4,11,17,23],head DPT dim_in 1024 features 256 out_channels [256,512,1024,1024])
  • 源实现:https://github.com/ByteDance-Seed/depth-anything-3(depth_anything_3.model.da3.DepthAnything3Net,MODEL_REGISTRY['da3metric-large'])
  • Revision:main(config.json model_name da3metric-large)
  • 许可证:Apache-2.0

任务与路由

项值
模型DA3METRIC-LARGE(revision main,0.334B params,1.27 GB safetensors)
架构DepthAnything3Net(ViT-L DINOv2 24 blocks dim1024 + DPT head 256/512/1024/1024,sky 分支)
任务计算机视觉 - 单目 metric 深度估计 depth-estimation(附加 sky 分割)
输入image [B,N,3,H,W] float32,H%14==0 W%14==0(本仓 640x480 -> longest 504 + nearest 14 -> 504x378)
输出depth [B,N,H,W] metric depth float32 + sky [B,N,H,W] 0-1 概率 + aux 空 dict
数据契约输入轴 [B,N,3,H,W],输出 [B,N,H,W];预处理 upper_bound_resize 最长边504 + nearest Multiple 14,cv2 INTER_AREA/CUBIC,ImageNet 归一化 mean [0.485,0.456,0.406] std [0.229,0.224,0.225];输出 metric depth 需乘 focal 得真实尺度
路由计算机视觉 depth-estimation(参考 depth-anything-3 官方 api,验收 depth/sky 数值一致性与性能)

环境

  • 平台:Ascend 910_9362 x2,CANN 8.5.1,npu-smi 25.5.5,npu:0 目标设备
  • Python 3.11.14,torch 2.9.0+cpu + torch_npu 2.9.0.post1+gitee7ba04,torchvision,safetensors,omegaconf,addict,einops,numpy<2,pillow,opencv-python-headless
  • 依赖见 requirements.txt:torch、torch_npu、torchvision、safetensors、omegaconf、addict、einops、numpy、pillow、opencv-python-headless
  • 源代码本地路径 /tmp/depth-anything-3/src(需 git clone https://github.com/ByteDance-Seed/depth-anything-3 后将 src 加入 sys.path)

安装

git clone https://github.com/ByteDance-Seed/depth-anything-3 /tmp/depth-anything-3
pip install -r requirements.txt
# 模型权重需从 https://huggingface.co/depth-anything/DA3METRIC-LARGE 下载至 /opt/atomgit/adapt-npu-agent/models/DA3METRIC-LARGE/model.safetensors

NPU 推理

python inference.py
  • 默认从本地 /opt/atomgit/adapt-npu-agent/models/DA3METRIC-LARGE 加载权重,回退 MODEL_DIR 环境变量
  • 显式 copy.deepcopy(cpu_model).to("npu:0") 与 tensor.to("npu:0"),日志打印 device/dtype/shape/耗时,前后 torch.npu.synchronize(),无 CPU fallback
  • 失败返回非零退出码,日志包含 [STATUS] SUCCESS

真实结果(本次运行)

  • 合成输入:确定性梯度+红矩形 640x480 RGB(seed 0),预处理后 504x378(H%14==0 W%14==0),tensor (1,1,3,378,504) range [-1.16,2.64] mean 0.467
  • CPU baseline(float32 inference,autocast 关闭):depth shape (1,1,378,504) mean 1.080080 std 0.055746 min 0.955258 max 1.222235 median 1.074717;sky mean 0.000066 max 0.128228
  • NPU(npu:0,autocast float16,synchronize 计时):depth shape (1,1,378,504) dtype float32(实际 autocast float16 计算后 float 输出)device npu:0 mean 1.083033 std 0.055748 min 0.958302 max 1.224869 median 1.077865;sky mean 0.000064 max 0.126724
  • 样本 depth[0,0,0:5,0:5] mean CPU 1.052297 vs NPU 首行 [1.0631,1.0589,1.0570,1.0542,1.0548]
  • 首轮 406.83 ms(含编译),稳定后 23-24 ms/iter

一致性

  • 保存 CPU/NPU depth 为 npy,运行 python .claude/skills/npu-adapt-skills/scripts/compare_outputs.py --task regression(实际脚本用 depth 通用回归阈值)
  • 结果:depth max_abs 4.12e-03 mean_abs 2.95e-03 median 2.93e-03;sky max_abs 5.37e-03 mean_abs 2.71e-06;finite True;shape 完全一致
  • 阈值:depth mean <0.005 & max <0.1 且 sky mean <0.002 & max <0.05 判定通过(FP16 autocast 误差容差,metric depth 尺度 ~1.0)
  • 验证无 CPU fallback:set(str(p.device) for p in model.parameters()) == {'npu:0'}
  • 另有 518x518 随机输入测试 max_abs 1.57e-03 mean 3.35e-04 通过 atol1e-3 rtol1e-3(workflow.log)

性能

  • 预热 3 次,正式 10 次,前后 torch.npu.synchronize(),batch 1
  • avg 23.57 ms min 23.24 max 24.58 p50 23.27 p90 24.29 p95 24.44 ms/iter(images)
  • 首轮/编译 ~24.58 ms(首个 timed iter,warmup 后)
  • 吞吐 42.43 images/s,H 378 W 504 dtype float16 autocast device npu:0
  • 权重 0.334B 参数 ~1.24 GB fp32 / 0.62 GB fp16,HBM 64GB 单卡充裕,npu-smi 基线 3.1GB

证据图

  • assets/agent_workflow.png - 工作流(侦察/下载/加载/NPU/一致性/性能/校验)
  • assets/npu_device_call.png - 设备调用(npu-smi、check_npu、参数与张量 npu:0)
  • assets/model_result.png - 默认推理完整输出(CPU/NPU stats、一致性、性能)
  • 图片由 xterm.js 根据本次真实日志生成(prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$),非手绘

限制

  • 固定合成图像(梯度+矩形),未用真实场景数据集评测 NYU/KITTI 指标,仅 smoke 验证数值一致性
  • FP16 autocast 在 NPU 上,CPU 使用 FP32,对比容差放宽至 5e-03 mean,不代表逐位相等
  • 单卡 FP32/FP16,未测 BF16、批量 >1、变分辨率或多视图输入
  • 依赖 depth-anything-3 源码路径 /tmp/depth-anything-3/src,非 pip 包

致谢

ByteDance Seed 团队 Depth Anything 3 官方实现与权重。