COCO8-Grayscale 数据集
简介#
Ultralytics COCO8-Grayscale 数据集是一个精简的对象检测数据集,包含 COCO train 2017 数据集中的前 8 张图像,并已转换为灰度格式,其中 4 张用于训练,4 张用于验证。该数据集专为快速测试、调试以及使用 YOLO 灰度模型和训练流水线进行实验而设计。其规模小、易于管理,同时具备足够的多样性,可在扩展到更大数据集之前有效检查流程是否正常。
观看: 如何使用灰度和多光谱数据集训练 Ultralytics YOLO | 多通道 VisionAI 🚀
数据集结构#
COCO8-Grayscale 与 COCO8 一致,包含 COCO train 2017 集的前 8 张图像,其中 4 张用于训练,4 张用于验证,并使用 80 个 COCO 类别名称进行标注;但每张图像都以单通道 (channels: 1) 灰度图像的形式存储,采用 YOLO 标注格式:
coco8-grayscale/
├── images/
│ ├── train/ # 4 images
│ └── val/ # 4 images
└── labels/
├── train/
└── val/在 Ultralytics Platform 上探索 COCO8-Grayscale,浏览带有标注叠加层的每张图像,在 Charts 选项卡中查看类别分布和边界框热力图,并克隆数据集以在云端训练自己的模型。
数据集 YAML#
COCO8-Grayscale 数据集配置在 YAML 文件中定义,其中指定了数据集路径、类别名称和其他重要元数据。你可以在 Ultralytics GitHub 仓库中查看官方的 coco8-grayscale.yaml 文件。
要以灰度方式使用 RGB 图像进行训练,请在数据集 YAML 文件中添加 channels: 1。这样会在训练期间将所有图像转换为灰度,因此无需单独准备灰度数据集。
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# COCO8-Grayscale dataset (first 8 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/detect/coco8-grayscale
# Example usage: yolo train data=coco8-grayscale.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco8-grayscale ← downloads here (1 MB)
# 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: coco8-grayscale # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
channels: 1
# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-grayscale.zip用法#
首次启动训练时,系统会自动下载 COCO8-Grayscale 数据集(1 MB)。如需在 COCO8-Grayscale 上以 640 的图像尺寸训练一个 YOLO26n 模型,训练 100 个周期,请使用以下示例。
from ultralytics import YOLO
# 加载预训练的 YOLO26n 模型
model = YOLO("yolo26n.pt")
# 在 COCO8-Grayscale 上训练模型
results = model.train(data="coco8-grayscale.yaml", epochs=100, imgsz=640)示例图像和标注#
以下是 COCO8-Grayscale 数据集中的马赛克训练批次示例:
- 马赛克图像:此图像展示了一个训练批次,其中多张数据集图像通过马赛克增强合并在一起。马赛克增强增加了每个批次中对象和场景的多样性,有助于模型更好地适应不同的对象尺寸、宽高比和背景。
这项技术对 COCO8-Grayscale 这类小型数据集尤其有用,因为它能在训练期间充分利用每张图像。
引用与致谢#
如果你在研究或开发工作中使用 COCO 数据集,请引用以下论文:
@misc{lin2015microsoft,
title={Microsoft COCO: Common Objects in Context},
author={Tsung-Yi Lin and Michael Maire and Serge Belongie and Lubomir Bourdev and Ross Girshick and James Hays and Pietro Perona and Deva Ramanan and C. Lawrence Zitnick and Piotr Dollár},
year={2015},
eprint={1405.0312},
archivePrefix={arXiv},
primaryClass={cs.CV}
}特别感谢 COCO Consortium 持续为计算机视觉社区作出贡献。
常见问题#
Ultralytics COCO8-Grayscale 数据集专为快速测试和调试目标检测模型而设计。该数据集仅包含 8 张图像(4 张用于训练,4 张用于验证),非常适合用来验证 YOLO 训练流水线,并确保所有环节都能按预期运行,然后再扩展到更大的数据集。
你可以使用 Python 或 CLI 在 COCO8-Grayscale 上训练 YOLO26 模型:
训练示例from ultralytics import YOLO # 加载预训练的 YOLO26n 模型 model = YOLO("yolo26n.pt") # 在 COCO8-Grayscale 上训练模型 results = model.train(data="coco8-grayscale.yaml", epochs=100, imgsz=640)如需了解其他训练选项,请参阅 YOLO 训练文档。
COCO8-Grayscale 训练中使用的马赛克增强会在每个批次中将多张图像合并为一张。这会增加目标和背景的多样性,帮助 YOLO 模型更好地泛化到新场景。马赛克增强对小型数据集尤其有用,因为它能最大限度地利用每个训练步骤中的信息。
在 COCO8-Grayscale 上训练完成后,你可以通过 Python 或 CLI 使用模型的验证命令来验证 YOLO26 模型。该操作会使用标准指标评估模型性能。分步说明请参阅 YOLO 验证文档。
评论7
提出问题、分享结果,或帮助其他人。
arfan1181
Finally
1shkim-lp
Dear Ultralytics, Hello. I am a learner and a user of Ultralytics-YOLO Software. I am writing this post to ask questions about tracking Livestream color videos in grayscale.
At the moment, I am using Ultralytics for Classification/Segmentation/Tracking of my Livestream video. My livestream video contains 4 different types of connectors, which are moved by robots.
I have used the software well so far to classify/segment/track the 4 connectors in Livestream color video I tracked the Livestream video with
results = model.track(source="0", show=Trune, save=True), which displayed live results with "0" window. I was happy with the result.Now, I want to test the performance for a real scenario, where the Livestream camera will aceept only B/W images (The equipment has not been installed yet and I am trying to emulate future situation). I learned how to train models in B/W images with simple addition of channels = 1 . However, I still don't know how to track a Livestream video (where images are imported in color) in B/W scales and output them in B/W in "0" window.
Would there be an easy method to invoke results = model.track(source="0", show=Ture, save=True) , but classify/segment/track in B/W scale and output them in B/W as well?Thank you for your assistance!
Glenn JocherUltralyticsThere’s no built-in switch in
model.track(source=0, ...)to force grayscale preprocessing for a webcam stream, so the simplest way to emulate a B/W camera is to read frames with OpenCV, convert to grayscale, then replicate back to 3 channels (GRAY2BGR) so it works with any YOLO model, and display/save the result (training-side grayscale is covered on the COCO8-Grayscale dataset page).import cv2 from ultralytics import YOLO model = YOLO("best.pt") # your det/seg model cap = cv2.VideoCapture(0) while True: ok, frame = cap.read() if not ok: break gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) frame_bw3 = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR) # BW content, kept 3-channel results = model.track(source=frame_bw3, persist=True, verbose=False) annotated = results[0].plot() # BGR annotated_gray = cv2.cvtColor(annotated, cv2.COLOR_BGR2GRAY) cv2.imshow("0", annotated_gray) if cv2.waitKey(1) == 27: # ESC to quit break cap.release() cv2.destroyAllWindows()1shkim-lp
Thank you for such a prompt and precise answer!
Glenn JocherUltralyticsGlad it helped—if you end up training a
channels: 1model you can usually skipGRAY2BGRand feed the grayscale frame directly as(H, W)or(H, W, 1)(the loader will expand 2D grayscale to 1 channel), and feel free to drop any follow-up questions here so the Ultralytics team sees them (see the COCO8-Grayscale dataset docs).
zjjzeng
Hello, I did not notice this page before, so I trained my model on default rgb 3 channels and then predicted. Actually, all my native dataset images are gray images, I used a numpy operation to manually transfer it before training. I wonder that if I change channels to 1, will I be able to gain any improvements on my model. And do I need to modify both data.yaml and my customized yolo11n.yaml, right?
Glenn JocherUltralyticsGreat question—set channels: 1 in your dataset YAML and train; you don’t need to modify your custom yolo11n.yaml as the model’s first layer adapts automatically; if you previously replicated grayscale to 3 channels, accuracy differences are usually small while 1-channel can save memory, so a quick A/B run is the best way to confirm; for more on multi-channel handling, see the COCO8-Multispectral dataset page.



