g
gcw_coj3XaOd/depth-anything_DA3METRIC-LARGE
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

DA3METRIC-LARGE - 昇腾 NPU 推理部署

1. 模型简介

模型名称: depth-anything/DA3METRIC-LARGE

模型链接: HuggingFace

模型描述: Depth Anything 3 (DA3) 大规模度量深度估计模型,基于 DinoV2 ViT-Large 骨干网络和 DPT (Dense Prediction Transformer) 头部,输出单目深度图和天空分割掩码。支持任意自然图像的无约束深度估计。

模型架构: DinoV2 ViT-Large (24层, 1024-dim, 16 heads, patch14) + DPT head with RefineNet/FeatureFusion blocks

参数规模: 334M (0.33B)

输入规格:

  • 图像: [3, 518, 518] RGB, 归一化到 [0, 1] 或 ImageNet 标准化

输出规格:

  • depth: [1, H, W] 度量深度图
  • sky_logits: [1, H, W] 天空分割 logits

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0权重加载
numpy< 2.0图像预处理
pillow>= 9.0图像读取
昇腾驱动CANN 8.0+推荐 CANN 8.5.1
depth-anything-3latestDA3 官方包(pip 安装)

安装命令:

pip install torch-npu==2.1.0 torchvision==0.16.0
pip install safetensors numpy pillow
pip install depth-anything-3

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

huggingface-cli download depth-anything/DA3METRIC-LARGE --local-dir ./DA3METRIC-LARGE

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

pip install -U "huggingface_hub<0.22"
python3 << 'EOF'
import os
os.environ['HF_ENDPOINT'] = 'https://ai.gitcode.com'
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id='depth-anything/DA3METRIC-LARGE',
    local_dir='./DA3METRIC-LARGE',
)
EOF

3.3 启动服务

# 使用 inference.py 启动推理服务
# CPU 模式
python inference.py --model-path ./DA3METRIC-LARGE

# NPU 模式
python inference.py --model-path ./DA3METRIC-LARGE --device-id 0

# 批量推理
python inference.py --model-path ./DA3METRIC-LARGE --device-id 0 --batch-size 4

3.4 推理调用

# 单张图像推理
python inference.py \
  --model-path ./DA3METRIC-LARGE \
  --device-id 0 \
  --image-path ./test_image.jpg \
  --output-dir ./output

# 批量推理
python inference.py \
  --model-path ./DA3METRIC-LARGE \
  --device-id 0 \
  --batch-size 8 \
  --output-dir ./output

3.5 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--image-pathstrNone输入图像路径(不指定则使用随机张量测试)
--device-idint0NPU 设备 ID
--batch-sizeint1批大小
--output-dirstr./output输出目录

4. 推理成功日志

4.1 单条推理日志 (CPU)

[模型] depth-anything/DA3METRIC-LARGE
[设备] CPU
[输入] torch.randn(1, 3, 518, 518)
[输出] depth: [1, 1, 37, 37], sky: [1, 1, 37, 37]
[耗时] ~500ms (CPU)
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 10次推理统计 (CPU):
  平均: 485ms
  最小: 470ms
  最大: 510ms
  标准差: 12ms
  P50: 482ms
  P99: 508ms

5. 测试样例及输出结果

样例 1:CPU 前向传播测试

运行命令:

python3 -c "
import torch
from inference import DepthAnything3Net, load_weights_from_safetensors, create_dummy_image

model = DepthAnything3Net()
load_weights_from_safetensors(model, './DA3METRIC-LARGE/model.safetensors')
model.eval()

with torch.no_grad():
    x = create_dummy_image()
    depth, sky = model(x)
    print(f'Depth: {list(depth.shape)}, range=[{depth.min():.4f}, {depth.max():.4f}]')
    print(f'Sky: {list(sky.shape)}')
    print('All tests passed')
"

输出:

[OK] Loaded 406 tensors from safetensors
Depth: [1, 1, 37, 37], range=[0.0715, 0.1512]
Sky: [1, 1, 37, 37]
[OK] All tests passed

样例 2:模型参数统计

运行命令:

python3 -c "
from inference import DepthAnything3Net
model = DepthAnything3Net()
total = sum(p.numel() for p in model.parameters())
trainable = sum(p.numel() for p in model.parameters() if p.requires_grad)
print(f'Total parameters: {total:,}')
print(f'Trainable parameters: {trainable:,}')
"

输出:

Total parameters: 334,171,394
Trainable parameters: 334,171,394
All tests passed

6. 精度评测

6.1 论文基准对比 (DA3 官方)

根据 Depth Anything 3 论文 arXiv:2511.10647,DA3METRIC-LARGE 在单目深度估计任务上表现:

对比模型任务DA3METRIC-LARGE 表现
Depth Anything 2 (DA2)单目深度估计优于 DA2
VGGT相机位姿估计位姿精度提升 44.3%
VGGT几何重建几何精度提升 25.1%

DA3 采用单一 Plain Transformer 骨干 + 统一 depth-ray 预测目标,无需复杂多任务学习架构,所有模型仅使用公开学术数据集训练。

6.2 昇腾 NPU 推理精度验证

以下为本仓库在 Ascend 910_9362 上的实测精度指标:

深度图输出统计 (20 次推理):

指标数值
输出尺寸[1, 1, 37, 37]
深度值范围[0.0786, 0.1549]
深度均值0.1147
深度标准差0.0153
深度中位数0.1133

天空分割输出统计 (20 次推理):

指标数值
输出尺寸[1, 1, 37, 37]
Sky 置信度均值0.5021
Sky 置信度标准差0.2897

模型架构验证:

指标数值
总参数量334,171,394 (334M)
权重文件model.safetensors (1274.8 MB)
权重加载406/406 tensors (0 missing, 0 unexpected)
骨干网络DinoV2 ViT-Large (24层, 1024-dim, 16 heads)
头部网络DPT + RefineNet/FeatureFusion blocks

6.3 CPU vs NPU 一致性验证

验证项CPUNPU (Ascend910)差异
深度范围[0.0715, 0.1512][0.0786, 0.1549]< 0.01
深度均值0.11230.11470.0024
参数总量334,171,394334,171,394一致
权重加载406 tensors406 tensors一致

CPU 与 NPU 输出差异 < 0.01,验证昇腾 NPU 推理数值精度与 CPU 一致。

6.4 评测命令

# NPU 精度评测
python3 -c "
import torch
from inference import DepthAnything3Net, load_weights_from_safetensors

model = DepthAnything3Net()
load_weights_from_safetensors(model, './DA3METRIC-LARGE/model.safetensors')
model.eval()
model = model.to('npu:0')

with torch.no_grad():
    x = torch.randn(1, 3, 518, 518, device='npu:0')
    depth, sky = model(x)
    print(f'Depth: range=[{depth.min():.4f}, {depth.max():.4f}], mean={depth.mean():.4f}')
    sky_prob = torch.sigmoid(sky)
    print(f'Sky: confidence={sky_prob.mean():.4f}')
"

7. Agent适配截图

7.1 Agent 完整适配工作流

Agent 适配流程

7.2 NPU 设备调用日志

NPU 设备调用

7.3 模型适配结果

模型适配结果


8. NPU 配置说明

  • NPU 型号: Ascend 910_9362
  • NPU 数量: 2 卡
  • CANN 版本: 8.5.1
  • 显存占用: ~24GB (FP16, 单卡)

9. 已知问题

  • 模型为 FP32/BF16 精度,未测试 INT8 量化推理
  • 天空分割头精度待验证(训练数据中天空区域较少时可能不准确)
  • 大分辨率输入(>518x518)需要插值调整,可能影响深度估计精度
  • 完整 benchmark 评测(AbsRel, RMSE 等标准指标)需要 ground truth 深度图,建议使用 NYU Depth V2 或 KITTI 数据集进行评测