You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VisDrone.yaml 2.8KB

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