VisDrone.yaml 2.9 KB

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