Link to this section深度估计数据集概述#
单目深度估计为图像中的每个像素分配一个以米为单位的浮点深度值。训练目标是一个存储为 .npy float32 数组的密集逐像素深度图。每个值代表从相机到相应场景点的距离。
本指南介绍了 Ultralytics YOLO 深度估计模型所使用的数据集格式,并列出了可用于训练和验证的内置数据集配置。
Link to this section支持的数据集格式#
Link to this sectionNPY 深度图格式#
每个训练样本由一张 RGB 图像和一个配对的 .npy 深度文件组成。深度文件存储了一个形状为 (H, W) 的 2D float32 NumPy 数组,其中的值是以米为单位的深度。
- 深度文件必须使用
.npy扩展名并包含一个 float32 数组。 - 每个深度文件应与其对应的图像文件具有相同的文件名(例如,
scene_001.npy与scene_001.jpg配对)。 - 数据集加载器通过将文件路径中的
images目录组件替换为depth,并将图像扩展名替换为.npy来查找深度文件。 - 深度
≤ 0的像素被视为无效,并在损失和指标计算中被排除。
标准布局将图像和深度图保存在并行文件夹中:
dataset/
├── images/
│ ├── train/
│ └── val/
└── depth/
├── train/
└── val/例如,位于 images/train/scene_001.jpg 的图像与位于 depth/train/scene_001.npy 的深度图配对。
Link to this section数据集 YAML 格式#
深度估计数据集通过 YAML 文件进行配置。主要字段包括:
| 键 | 描述 |
|---|---|
path | 数据集根目录。 |
train | 相对于 path 的训练图像路径,或绝对路径。 |
val | 相对于 path 的验证图像路径,或绝对路径。 |
test | 可选的测试图像路径。 |
nc | 类别数量 —— 深度估计中始终为 1。 |
names | 类别名称映射 —— 始终为 {0: depth}。 |
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# NYU Depth V2 dataset for monocular depth estimation
# Documentation: https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html
# 795 train + 654 val (Eigen test split) images, 480x640, indoor scenes, depth in meters
# Example usage: yolo depth train data=nyu-depth.yaml model=yolo26n-depth.pt
# parent
# ├── ultralytics
# └── datasets
# └── nyu-depth ← downloads here (≈1.5 GB)
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: nyu-depth # dataset root dir (relative to Ultralytics settings 'datasets_dir')
train: images/train # train images (relative to 'path') 795 images
val: images/val # val images (relative to 'path') 654 images
# Depth maps are paired .npy files (float32, meters) under depth/<split>/, resolved by
# swapping '/images/' -> '/depth/' on each image path.
# Classes
nc: 1
names:
0: depth
channels: 3
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/nyu-depth.zipLink to this section用法#
使用 Python 或 CLI 训练 YOLO26 深度估计模型:
from ultralytics import YOLO
# Load a pretrained depth model
model = YOLO("yolo26n-depth.pt")
# Train on the NYU Depth V2 dataset
results = model.train(data="nyu-depth.yaml", epochs=100, imgsz=640)Link to this section支持的数据集#
YOLO26 深度模型是在广泛的多数据集组合(约 219 万张图像)上预训练的,涵盖了室内(≤10 米)到室外(约 80 米)的范围,然后在五个基准测试上进行了零样本评估。每个数据集都有一个专门的页面:
调试
- Depth8 — 包含 8 张 SUN RGB-D 图像的 1.3 MB 自动下载归档文件,用于快速管道测试
预训练源
- ARKitScenes — 真实室内,Apple ARKit LiDAR(最大的真实数据源)
- SUN RGB-D — 真实室内,多传感器 RGB-D
- DIODE — 真实室内 + 室外,密集激光扫描仪地面实况
- Hypersim — 合成照片级真实室内
- TartanAir — 合成,多样化环境
- Virtual KITTI 2 — 合成室外驾驶
- KITTI — 真实室外驾驶,Velodyne LiDAR(也是一个评估基准)
- ImageNet (伪标签) — 伪标签蒸馏集,最大的单一来源
评估基准
- NYU Depth V2 — 主要室内基准
- KITTI Eigen — 室外驾驶基准
- ETH3D — 高精度室内 + 室外
- Make3D — 室外,分布外数据
- iBims-1 — 高质量室内(边缘和平面)
这些基准上的每模型准确率和可下载的预训练权重列在 Depth Estimation 任务页面上。数据集 YAML 的 train 字段列出多个图像目录,可将这些来源合并用于大规模混合训练。
Link to this section添加你自己的数据集#
- 将 RGB 图像保存在如
images/train和images/val等拆分文件夹下。 - Save one
.npyfloat32 depth array per image under the matchingdepth/trainanddepth/valfolders using the same file stem as the image. - 确保深度值以米为单位,并且无效或缺失的像素使用
0或负值。 - 创建一个包含
path、train、val、nc: 1和names: {0: depth}的数据集 YAML 文件。
path: path/to/my-depth-dataset
train: images/train
val: images/val
nc: 1
names:
0: depthLink to this section常见问题解答#
Link to this section深度图应该使用什么文件格式?#
深度图必须保存为 NumPy .npy 文件,其中包含形状为 (H, W) 的 float32 数组。每个元素存储对应图像像素的深度(单位:米)。请勿使用 PNG 或 16 位整数格式 —— 加载器需要原始浮点数组。
Link to this section如何处理无效的深度像素?#
深度值 ≤ 0 的像素被视为无效,并在损失计算和指标评估中被屏蔽。这涵盖了无法可靠测量深度的传感器噪声、天空区域和反射表面。
Link to this section评估使用什么指标?#
深度估计验证报告使用标准的 Depth Anything 指标集:
- delta1 / delta2 / delta3 — 处于 1.25×、1.25²×、1.25³× 阈值内的像素百分比。数值越高越好。
- abs_rel — 平均绝对相对误差。数值越低越好。
- rmse — 均方根误差(单位:米)。数值越低越好。
- silog — 尺度不变对数误差。数值越低越好。
Link to this section深度文件名需要与图像文件名匹配吗?#
是的。每个深度 .npy 文件必须与对应的图像具有相同的文件名。加载器通过将 images 目录组件替换为 depth 并将图像扩展名替换为 .npy 来推导深度路径。在(缓存的)数据集扫描过程中,深度文件丢失或无法读取的图像会被丢弃并发出警告,这与损坏的图像处理方式完全相同;如果没有找到任何有效的图像-深度对,则会引发错误。