VisDrone2019数据集转YOLO格式
今天跑VisDrone2019发现数据集标注格式不是YOLO的 在CSDN里找的Python源码做了格式转换源作者没有保存下来记录如下1、转YOLOimport os from pathlib import Path from PIL import Image from tqdm import tqdm def visdrone2yolo(dir): def convert_box(size, box): # Convert VisDrone box to YOLO CxCywh box,坐标进行了归一化 dw 1. / size[0] dh 1. / size[1] return (box[0] box[2] / 2) * dw, (box[1] box[3] / 2) * dh, box[2] * dw, box[3] * dh # (dir / labels).mkdir(parentsTrue, exist_okTrue) # make labels directory (dir / Annotations_YOLO).mkdir(parentsTrue, exist_okTrue) # make labels directory pbar tqdm((dir / annotations).glob(*.txt), descfConverting {dir}) for f in pbar: try: img_size Image.open((dir / images / f.name).with_suffix(.jpg)).size lines [] with open(f, r) as file: # read annotation.txt for row in [x.split(,) for x in file.read().strip().splitlines()]: if row[4] 0: # VisDrone ignored regions class 0 continue cls int(row[5]) - 1 box convert_box(img_size, tuple(map(int, row[:4]))) lines.append(f{cls} { .join(f{x:.6f} for x in box)}\n) # 构建输出文件路径 output_path str(f).replace(os.sep annotations os.sep, os.sep Annotations_YOLO os.sep) with open(output_path, w) as fl: fl.writelines(lines) # write label.txt except Exception as e: print(fError processing {f}: {e}) dir Path(rD:\VisDrone2019) # dataset文件夹下Visdrone2019文件夹路径 # Convert # for d in [VisDrone2019-DET-train, VisDrone2019-DET-val, VisDrone2019-DET-test-dev]: # visdrone2yolo(dir / d) # convert VisDrone annotations to YOLO labels #visdrone2yolo(dir / VisDrone2019-DET-test-dev) # convert VisDrone annotations to YOLO labels visdrone2yolo(dir / VisDrone2019-DET-train)2、增加classes.txt文件方便LabelImage中查看0: pedestrian 1: people 2: bicycle 3: car 4: van 5: truck 6: tricycle 7: awning-tricycle 8: bus 9: motor3、启动LabelImage查看标注结果4、配置YOLO项目源码开始训练
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2569660.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!