Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

VisDrone.yaml 2.9 KB

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

Press p or to see the previous file or, n or to see the next file

Comments

Loading...