模型名称: 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)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| 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-3 | latest | DA3 官方包(pip 安装) |
安装命令:
pip install torch-npu==2.1.0 torchvision==0.16.0
pip install safetensors numpy pillow
pip install depth-anything-3# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"方式一: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# 使用 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# 单张图像推理
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| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 |
| --image-path | str | None | 输入图像路径(不指定则使用随机张量测试) |
| --device-id | int | 0 | NPU 设备 ID |
| --batch-size | int | 1 | 批大小 |
| --output-dir | str | ./output | 输出目录 |
[模型] depth-anything/DA3METRIC-LARGE
[设备] CPU
[输入] torch.randn(1, 3, 518, 518)
[输出] depth: [1, 1, 37, 37], sky: [1, 1, 37, 37]
[耗时] ~500ms (CPU)
[状态] SUCCESS[基准测试] 10次推理统计 (CPU):
平均: 485ms
最小: 470ms
最大: 510ms
标准差: 12ms
P50: 482ms
P99: 508ms运行命令:
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运行命令:
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根据 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 预测目标,无需复杂多任务学习架构,所有模型仅使用公开学术数据集训练。
以下为本仓库在 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 |
| 验证项 | CPU | NPU (Ascend910) | 差异 |
|---|---|---|---|
| 深度范围 | [0.0715, 0.1512] | [0.0786, 0.1549] | < 0.01 |
| 深度均值 | 0.1123 | 0.1147 | 0.0024 |
| 参数总量 | 334,171,394 | 334,171,394 | 一致 |
| 权重加载 | 406 tensors | 406 tensors | 一致 |
CPU 与 NPU 输出差异 < 0.01,验证昇腾 NPU 推理数值精度与 CPU 一致。
# 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}')
"

