File size: 5,455 Bytes
bf7e5ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1157d4
 
 
 
 
 
 
 
 
 
 
 
bf7e5ca
e1157d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
dataset_info:
  features:
  - name: image_id
    dtype: int64
  - name: image
    dtype: image
  - name: width
    dtype: int32
  - name: height
    dtype: int32
  - name: objects
    struct:
    - name: id
      list: int64
    - name: area
      list: int64
    - name: bbox
      list:
        list: float32
        length: 4
    - name: category
      list: int64
  splits:
  - name: train
    num_bytes: 31928785
    num_examples: 500
  - name: validation
    num_bytes: 7004874
    num_examples: 100
  - name: test
    num_bytes: 3954856
    num_examples: 50
  download_size: 42902433
  dataset_size: 42888515
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
  - split: validation
    path: data/validation-*
  - split: test
    path: data/test-*
task_categories:
- object-detection
tags:
- yolo
- ultralytics
- yolov8
- yolov11
- detection
- synthetic
license: apache-2.0
size_categories:
- n<1K
---

# 🎯 YOLO Object Detection Dataset

A synthetic object detection dataset with **5 classes**, ready for training YOLOv8/v11 models.

## πŸ“Š Dataset Summary

| | Train | Validation | Test |
|---|---|---|---|
| **Images** | 500 | 100 | 50 |
| **Hard negatives** | 75 (15%) | 15 (15%) | 7 (15%) |
| **Image size** | 640Γ—640 | 640Γ—640 | 640Γ—640 |

## 🏷️ Classes

| ID | Class | Visual |
|---|---|---|
| 0 | `car` | Red car-shaped rectangles with windows & wheels |
| 1 | `person` | Blue stick figures with body parts |
| 2 | `dog` | Brown dog shapes with legs & tail |
| 3 | `cat` | Orange cat shapes with ears & eyes |
| 4 | `bicycle` | Green bicycle with wheels & frame |

## πŸ“ Two Formats Available

### 1. HF Datasets (Parquet) β€” Browse & Load Programmatically
```python
from datasets import load_dataset
ds = load_dataset("dharshanzeb/yolo-detection-dataset")
print(ds["train"][0])
# {'image_id': 0, 'image': <PIL>, 'width': 640, 'height': 640,
#  'objects': {'id': [...], 'area': [...], 'bbox': [[x,y,w,h], ...], 'category': [...]}}
```

### 2. YOLO Format (Zips) β€” Direct Training with Ultralytics
Download from [`yolo_format/`](yolo_format/):
- `train.zip` β€” 500 images + labels
- `val.zip` β€” 100 images + labels
- `test.zip` β€” 50 images + labels
- `data.yaml` β€” YOLO config file

**Annotation format** (YOLO txt β€” one `.txt` per image):
```
<class_id> <x_center> <y_center> <width> <height>
# All values normalized 0-1
0 0.492188 0.403125 0.212500 0.315625
1 0.720312 0.150000 0.080000 0.120000
```

## πŸš€ Train YOLOv8 (Quick Start)

### Google Colab / Local
```python
# Install
!pip install ultralytics

from ultralytics import YOLO

# Download and prepare dataset
from huggingface_hub import hf_hub_download
import zipfile, os

for split in ["train", "val", "test"]:
    zip_path = hf_hub_download(
        repo_id="dharshanzeb/yolo-detection-dataset",
        filename=f"yolo_format/{split}.zip",
        repo_type="dataset"
    )
    with zipfile.ZipFile(zip_path) as z:
        z.extractall("./dataset/")

# Download data.yaml
yaml_path = hf_hub_download(
    repo_id="dharshanzeb/yolo-detection-dataset",
    filename="yolo_format/data.yaml",
    repo_type="dataset"
)

# Update path in data.yaml to point to extracted folder
import yaml
with open(yaml_path) as f:
    cfg = yaml.safe_load(f)
cfg["path"] = os.path.abspath("./dataset")
with open("data.yaml", "w") as f:
    yaml.dump(cfg, f)

# Train!
model = YOLO("yolov8n.pt")  # nano model for fast training
results = model.train(
    data="data.yaml",
    epochs=50,
    imgsz=640,
    batch=16,
    device=0,          # GPU
    pretrained=True,
    mosaic=1.0,
    mixup=0.1,
    project="runs/train",
    name="yolo_custom",
)

# Evaluate
metrics = model.val()
print(f"mAP50: {metrics.box.map50:.3f}")
print(f"mAP50-95: {metrics.box.map:.3f}")

# Predict
results = model.predict("test_image.jpg", conf=0.25)
results[0].show()
```

### Convert HF Dataset β†’ YOLO Format (Alternative)
```python
from datasets import load_dataset
from pathlib import Path

ds = load_dataset("dharshanzeb/yolo-detection-dataset")

for split_name, split_key in [("train","train"), ("val","validation"), ("test","test")]:
    img_dir = Path(f"dataset/images/{split_name}")
    lbl_dir = Path(f"dataset/labels/{split_name}")
    img_dir.mkdir(parents=True, exist_ok=True)
    lbl_dir.mkdir(parents=True, exist_ok=True)

    for idx, row in enumerate(ds[split_key]):
        stem = f"img_{idx:05d}"
        row["image"].save(img_dir / f"{stem}.jpg")
        
        lines = []
        W, H = row["width"], row["height"]
        for bbox, cat in zip(row["objects"]["bbox"], row["objects"]["category"]):
            x, y, w, h = bbox
            cx, cy = (x + w/2) / W, (y + h/2) / H
            lines.append(f"{cat} {cx:.6f} {cy:.6f} {w/W:.6f} {h/H:.6f}")
        
        with open(lbl_dir / f"{stem}.txt", "w") as f:
            f.write("\n".join(lines))
```

## πŸ“‹ Dataset Details

- **Hard negatives**: 15% of images contain no objects (empty label files). This is critical for reducing false positives during training β€” a technique from the synthetic-to-real YOLO paper (arXiv:2509.15045).
- **Backgrounds**: Gradient and textured backgrounds with noise for visual diversity.
- **Augmentation-ready**: Designed for use with YOLO's built-in Mosaic + Mixup augmentations.
- **Bounding boxes**: COCO format `[x_min, y_min, width, height]` in the HF dataset; YOLO normalized format in the zip files.

## πŸ“œ License

Apache 2.0