Link to this sectionCityscapes 数据集#
Cityscapes 数据集是一个大规模语义分割基准,包含在欧洲 50 个城市拍摄的城市街道场景,具有 2,975 张精细标注的训练图像和 500 张验证图像,涵盖 19 个类别。它是用于自动驾驶研究和使用 Ultralytics YOLO 模型进行城市场景理解的最常用数据集之一。
Link to this section主要特性#
- Cityscapes 精细标注包含 19 个类别的 2,975 张训练图像和 500 张验证图像;该存档还包含 1,525 张测试图像,但其发布的掩码仅标记了自车和图像边界——真实类别标注未公开,官方测试集评分需要向 Cityscapes 评估服务器提交预测结果。
- 该数据集涵盖 19 个评估类别,横跨平面、人类、车辆、建筑、物体、自然和天空等类别。
- Cityscapes 提供标准化的评估指标,如用于语义分割的平均交并比 (mIoU),从而实现对模型性能的有效比较。
- 在开始下载约 11 GB 的手动文件之前,建议先使用包含 8 张图像的 Cityscapes8 子集来测试你的训练流程。
Link to this section数据集结构#
Ultralytics 配置要求在准备后采用以下布局:
cityscapes/
├── images/
│ ├── train/
│ ├── val/
│ └── test/
└── masks/
├── train/
├── val/
└── test/Cityscapes 没有自动存档下载功能。请在 Cityscapes 网站上创建一个账户,然后下载 leftImg8bit_trainvaltest.zip 和 gtFine_trainvaltest.zip 压缩包(合计约 11 GB),并将两者提取到 cityscapes 数据集根目录中。Ultralytics 会在你第一次训练时自动将其重组为 images/ 和 masks/ 布局。
语义掩码是单通道 PNG 文件。原始 Cityscapes 标签 ID 通过 label_mapping 部分映射为标准的 19 个训练 ID,被忽略或无效的标签被映射为 255,以便在训练和评估中将其排除。
公开发布的 gtFine/test 掩码仅标记了自车和图像边界区域——所有其他类别均为无效。请在 val 拆分集上计算 mIoU 以进行本地评估;官方测试集评分需要向 Cityscapes 评估服务器提交预测。
Link to this section应用#
Cityscapes 被广泛用于训练和评估语义分割中的深度学习模型,特别是在自动驾驶、高级驾驶辅助系统 (ADAS) 和城市机器人领域。
其高分辨率图像和详细的标注也使其在实时场景解析、车道与障碍物理解以及任何需要对复杂城市环境进行密集像素级理解的任务研究中极具价值。预训练的 YOLO26 语义分割模型在 Cityscapes 验证集上最高可达 83.6 mIoU —— 请参阅语义分割模型页面获取完整的基准表。Cityscapes 标注也可在 Ultralytics 平台上获取,用于浏览和数据集管理。
Link to this section数据集 YAML#
数据集 YAML 文件定义了 Cityscapes 的路径、类、掩码目录和标签映射。cityscapes.yaml 文件维护在 https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/cityscapes.yaml。
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# Cityscapes semantic segmentation dataset (19 classes)
# Documentation: https://docs.ultralytics.com/datasets/semantic/cityscapes
# Example usage: yolo semantic train data=cityscapes.yaml model=yolo26n-sem.pt
# parent
# ├── ultralytics
# └── datasets
# └── cityscapes ← downloads here (11 GB)
# └── images
# └── masks
# Dataset root directory
path: cityscapes # dataset root dir
train: images/train # train images (relative to 'path') 2975 images
val: images/val # val images (relative to 'path') 500 images
test: images/test # test images (relative to 'path') 1525 images
masks_dir: masks # semantic mask directory
# Cityscapes 19-class labels
names:
0: road
1: sidewalk
2: building
3: wall
4: fence
5: pole
6: traffic light
7: traffic sign
8: vegetation
9: terrain
10: sky
11: person
12: rider
13: car
14: truck
15: bus
16: train
17: motorcycle
18: bicycle
# Map source label IDs to train IDs; ignore_label is converted to 255.
label_mapping:
-1: ignore_label
0: ignore_label
1: ignore_label
2: ignore_label
3: ignore_label
4: ignore_label
5: ignore_label
6: ignore_label
7: 0
8: 1
9: ignore_label
10: ignore_label
11: 2
12: 3
13: 4
14: ignore_label
15: ignore_label
16: ignore_label
17: 5
18: ignore_label
19: 6
20: 7
21: 8
22: 9
23: 10
24: 11
25: 12
26: 13
27: 14
28: 15
29: ignore_label
30: ignore_label
31: 16
32: 17
33: 18
# Preparation script (requires manual Cityscapes download)
download: |
from pathlib import Path
from shutil import copy2
cityscapes_dir = Path(yaml["path"]) # dataset root dir
# Download and extract the official Cityscapes leftImg8bit and gtFine archives into cityscapes_dir first.
leftimg8bit_dir = cityscapes_dir / "leftImg8bit"
gtfine_dir = cityscapes_dir / "gtFine"
for split in ("train", "val", "test"):
print(f"Processing {split} set")
src_image_dir = leftimg8bit_dir / split
dst_image_dir = cityscapes_dir / "images" / split
dst_mask_dir = cityscapes_dir / "masks" / split
dst_image_dir.mkdir(parents=True, exist_ok=True)
dst_mask_dir.mkdir(parents=True, exist_ok=True)
image_paths = sorted(src_image_dir.rglob("*_leftImg8bit.png"))
for image_path in image_paths:
relative_path = image_path.relative_to(src_image_dir)
mask_path = gtfine_dir / split / relative_path.parent / image_path.name.replace(
"_leftImg8bit.png", "_gtFine_labelIds.png"
)
if not mask_path.exists():
raise FileNotFoundError(f"Mask not found for {image_path}: {mask_path}")
image_name = image_path.name.replace("_leftImg8bit", "")
mask_name = mask_path.name.replace("_gtFine_labelIds", "")
copy2(image_path, dst_image_dir / image_name)
copy2(mask_path, dst_mask_dir / mask_name)Link to this section用法#
要使用 1024 的图像大小在 Cityscapes 数据集上训练 YOLO26n-sem 模型 100 个周期,你可以使用以下代码片段。有关可用参数的完整列表,请参阅模型训练页面。
from ultralytics import YOLO
# Load a model
model = YOLO("yolo26n-sem.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="cityscapes.yaml", epochs=100, imgsz=1024)Link to this section引用、许可和致谢#
Cityscapes 在自定义非商业许可下发布——可免费用于学术研究和评估,但商业使用、授权或再分发数据需要获得 Cityscapes 团队的单独许可。
如果你在研究或开发工作中使用了 Cityscapes 数据集,请引用以下论文:
@inproceedings{Cordts2016Cityscapes,
title={The Cityscapes Dataset for Semantic Urban Scene Understanding},
author={Cordts, Marius and Omran, Mohamed and Ramos, Sebastian and Rehfeld, Timo and Enzweiler, Markus and Benenson, Rodrigo and Franke, Uwe and Roth, Stefan and Schiele, Bernt},
booktitle={Proc. of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year={2016}
}我们要感谢 Cityscapes 团队为自动驾驶和计算机视觉社区创建并维护了这一宝贵的资源。有关 Cityscapes 数据集及其创建者的更多信息,请访问 Cityscapes 数据集网站。
Link to this section常见问题解答#
Link to this section什么是 Cityscapes 数据集,它对于计算机视觉为什么很重要?#
Cityscapes 数据集是一个大规模语义分割基准,涵盖 50 个欧洲城市的城市街道场景,被广泛用作自动驾驶和 ADAS 研究的标准参考。其 19 个精细标注的评估类别、高分辨率图像和标准化的平均交并比 (mIoU) 指标,使其成为最常被引用的密集场景理解模型基准之一。
Link to this section我该如何使用 Cityscapes 数据集训练 YOLO 模型?#
要使用 1024 的图像大小在 Cityscapes 数据集上训练 YOLO26n-sem 模型 100 个周期,你可以使用以下代码片段。有关可用参数的详细列表,请参阅模型训练页面。
from ultralytics import YOLO
# Load a model
model = YOLO("yolo26n-sem.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="cityscapes.yaml", epochs=100, imgsz=1024)Link to this sectionCityscapes 数据集是如何构建的?#
准备好后,数据集被组织成 images/{train,val,test}/ 和 masks/{train,val,test}/ 目录,每张图像都配有一个单通道 PNG 掩码。Ultralytics YAML 文件通过 masks_dir: masks 字段将每张图像与其掩码配对,并使用 label_mapping 将原始 Cityscapes 标签 ID 转换为标准的 19 个连续训练 ID,同时将忽略和无效标签映射为 255。test 拆分集的掩码仅标记自车和边界区域,因此请使用 val 进行本地 mIoU 检查。
Link to this section我需要手动下载 Cityscapes 吗?#
是的。在 Cityscapes 网站上创建一个账户并下载 leftImg8bit_trainvaltest.zip 和 gtFine_trainvaltest.zip 存档(合计约 11 GB)。将两者提取到 cityscapes 数据集根目录中——Ultralytics 会在你第一次训练时自动将其重新组织为预期的 images/ 和 masks/ 布局。
Link to this section为什么 Cityscapes 使用 label_mapping?#
Cityscapes 源掩码存储的原始标签 ID 与用于评估的 19 个训练 ID 不同。label_mapping 部分将有效标签转换为连续的类 ID 0–18,并将忽略和无效标签分配为 255,以便在训练和验证期间将其从损失函数和指标计算中排除。
Link to this sectionCityscapes 数据集可以免费用于商业用途吗?#
不可以。Cityscapes 是在非商业许可下发布的,该许可允许学术研究、教学和评估,但禁止商业使用、授权或销售该数据集及其衍生作品。有关商业授权选项,请直接联系 Cityscapes 团队。