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.

62 line
2.7KB

  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_folder
  5. # /VisDrone
  6. # /yolov5
  7. # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
  8. train: ../VisDrone/VisDrone2019-DET-train/images # 6471 images
  9. val: ../VisDrone/VisDrone2019-DET-val/images # 548 images
  10. test: ../VisDrone/VisDrone2019-DET-test-dev/images # 1610 images
  11. # number of classes
  12. nc: 10
  13. # class names
  14. names: [ 'pedestrian', 'people', 'bicycle', 'car', 'van', 'truck', 'tricycle', 'awning-tricycle', 'bus', 'motor' ]
  15. # download command/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('../VisDrone') # dataset directory
  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