VisDrone.yaml 3.0 KB

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