visdrone是一个无人机的目标检测数据集,在很多目标检测的论文中都能看到它的身影。
标签从0到11分别为’ignored regions’,‘pedestrian’,‘people’,‘bicycle’,‘car’,‘van’,
‘truck’,‘tricycle’,‘awning-tricycle’,‘bus’,‘motor’,‘others’
现在先要用mmdetection自己训练一下这个数据集,需要把他转化为coco数据集格式
分两步走:
1. 将annotations中的txt标签转化为xml文件
需要改的地方有注释,就是几个路径改一下即可
import os
from PIL import Image
# 把下面的root_dir路径改成你自己的路径即可
root_dir = r"D:\object_detection_data\datacovert\VisDrone2019-DET-val/"
annotations_dir = root_dir+"annotations/"
image_dir = root_dir + "images/"
xml_dir = root_dir+"Annotations_XML/" #在工作目录下创建Annotations_XML文件夹保存xml文件
# 下面的类别也换成你自己数据类别,也可适用于其他的数据集转换
class_name = ['ignored regions','pedestrian','people','bicycle','car','van',
'truck','tricycle','awning-tricycle','bus','motor','others']
for filename in os.listdir(annotations_dir):
fin = open(annotations_dir+filename, 'r')
image_name = filename.split('.')[0]
img = Image.open(image_dir+image_name+".jpg") # 若图像数据是“png”转换成“.png”即可
xml_name = xml_dir+image_name+'.xml'
with open(xml_name, 'w') as fout:
fout.write('<annotation>'+'\n')
fout.write('\t'+'<folder>VOC2007</folder>'+'\n')
fout.write('\t'+'<filename>'+image_name+'.jpg'+'</filename>'+'\n')
fout.write('\t'+'<source>'+'\n')
fout.write('\t\t'+'<database>'+'VisDrone2019-DET'+'</database>'+'\n')
fout.write('\t\t'+'<annotation>'+'VisDrone2019-DET'+'</annotation>'+'\n')
fout.write('\t\t'+'<image>'+'flickr'+'</image>'+'\n')
fout.write('\t\t'+'<flickrid>'+'Unspecified'+'</flickrid>'+'\n')
fout.write('\t'+'</source>'+'\n')
fout.write('\t'+'<owner>'+'\n')
fout.write('\t\t'+'<flickrid>'+'LJ'+'</flickrid>'+'\n')
fout.write('\t\t'+'<name>'+'LJ'+'</name>'+'\n')
fout.write('\t'+'</owner>'+'\n')
fout.write('\t'+'<size>'+'\n')
fout.write

本文介绍如何将VisDrone数据集转换为COCO格式,并使用MMDetection进行目标检测训练的过程。涉及XML到JSON的转换脚本及模型配置调整。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



