|
a |
|
b/data/VisDrone.yaml |
|
|
1 |
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license |
|
|
2 |
# VisDrone2019-DET dataset https://github.com/VisDrone/VisDrone-Dataset by Tianjin University |
|
|
3 |
# Example usage: python train.py --data VisDrone.yaml |
|
|
4 |
# parent |
|
|
5 |
# ├── yolov5 |
|
|
6 |
# └── datasets |
|
|
7 |
# └── VisDrone ← downloads here (2.3 GB) |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
# 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, ..] |
|
|
11 |
path: ../datasets/VisDrone # dataset root dir |
|
|
12 |
train: VisDrone2019-DET-train/images # train images (relative to 'path') 6471 images |
|
|
13 |
val: VisDrone2019-DET-val/images # val images (relative to 'path') 548 images |
|
|
14 |
test: VisDrone2019-DET-test-dev/images # test images (optional) 1610 images |
|
|
15 |
|
|
|
16 |
# Classes |
|
|
17 |
names: |
|
|
18 |
0: pedestrian |
|
|
19 |
1: people |
|
|
20 |
2: bicycle |
|
|
21 |
3: car |
|
|
22 |
4: van |
|
|
23 |
5: truck |
|
|
24 |
6: tricycle |
|
|
25 |
7: awning-tricycle |
|
|
26 |
8: bus |
|
|
27 |
9: motor |
|
|
28 |
|
|
|
29 |
|
|
|
30 |
# Download script/URL (optional) --------------------------------------------------------------------------------------- |
|
|
31 |
download: | |
|
|
32 |
from utils.general import download, os, Path |
|
|
33 |
|
|
|
34 |
def visdrone2yolo(dir): |
|
|
35 |
from PIL import Image |
|
|
36 |
from tqdm import tqdm |
|
|
37 |
|
|
|
38 |
def convert_box(size, box): |
|
|
39 |
# Convert VisDrone box to YOLO xywh box |
|
|
40 |
dw = 1. / size[0] |
|
|
41 |
dh = 1. / size[1] |
|
|
42 |
return (box[0] + box[2] / 2) * dw, (box[1] + box[3] / 2) * dh, box[2] * dw, box[3] * dh |
|
|
43 |
|
|
|
44 |
(dir / 'labels').mkdir(parents=True, exist_ok=True) # make labels directory |
|
|
45 |
pbar = tqdm((dir / 'annotations').glob('*.txt'), desc=f'Converting {dir}') |
|
|
46 |
for f in pbar: |
|
|
47 |
img_size = Image.open((dir / 'images' / f.name).with_suffix('.jpg')).size |
|
|
48 |
lines = [] |
|
|
49 |
with open(f, 'r') as file: # read annotation.txt |
|
|
50 |
for row in [x.split(',') for x in file.read().strip().splitlines()]: |
|
|
51 |
if row[4] == '0': # VisDrone 'ignored regions' class 0 |
|
|
52 |
continue |
|
|
53 |
cls = int(row[5]) - 1 |
|
|
54 |
box = convert_box(img_size, tuple(map(int, row[:4]))) |
|
|
55 |
lines.append(f"{cls} {' '.join(f'{x:.6f}' for x in box)}\n") |
|
|
56 |
with open(str(f).replace(os.sep + 'annotations' + os.sep, os.sep + 'labels' + os.sep), 'w') as fl: |
|
|
57 |
fl.writelines(lines) # write label.txt |
|
|
58 |
|
|
|
59 |
|
|
|
60 |
# Download |
|
|
61 |
dir = Path(yaml['path']) # dataset root dir |
|
|
62 |
urls = ['https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-train.zip', |
|
|
63 |
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-val.zip', |
|
|
64 |
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-dev.zip', |
|
|
65 |
'https://github.com/ultralytics/yolov5/releases/download/v1.0/VisDrone2019-DET-test-challenge.zip'] |
|
|
66 |
download(urls, dir=dir, curl=True, threads=4) |
|
|
67 |
|
|
|
68 |
# Convert |
|
|
69 |
for d in 'VisDrone2019-DET-train', 'VisDrone2019-DET-val', 'VisDrone2019-DET-test-dev': |
|
|
70 |
visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels |