Bootstrap

UA-DETRAC数据集转YOLO格式

一: 数据集下载

原官方数据集

链接:https://pan.baidu.com/s/1P_CeSIpJIYSA1dykmFhgYw
提取码: 7f4g

处理完成数据集(每10帧取一张)

嫌麻烦可以直接使用我处理完的

链接:https://pan.baidu.com/s/1OV5m4lcYmPVkXOOGuqUmXg
提取码:93m0

包含训练集8639张,验证集2231张,已按照yolo训练格式放置,即下即用!

二: 处理标注文件

先处理标注文件,UA-DETRAC提供的标注文件格式是VOC格式,需要先转为XML格式,然后再将每个XML文件转为YOLO文件。
下面提供两个代码,只需要修改文件放置目录

1. 将VOC转为XML格式

import xml.etree.ElementTree as ET
from xml.dom.minidom import Document
import os
import cv2
import time


def ConvertVOCXml(file_path="", file_name=""):
    tree = ET.parse(file_name)
    root = tree.getroot()
    # print(root.tag)

    num = 0  # 计数
    # 读xml操作

    frame_lists = []
    output_file_name = ""
    for child in root:

        if (child.tag == "frame"):
            # 创建dom文档
            doc = Document()
            # 创建根节点
            annotation = doc.createElement('annotation')
            # 根节点插入dom树
            doc.appendChild(annotation)

            # print(child.tag, child.attrib["num"])
            pic_id = child.attrib["num"].zfill(5)
            # print(pic_id)
            output_file_name = root.attrib["name"] + "__img" + pic_id + ".xml"
            #  print(output_file_name)

            folder = doc.createElement("folder")
            folder.appendChild(doc.createTextNode("VOC2007"))
            annotation.appendChild(folder)

            filename = doc.createElement("filename")
            pic_name = "img" + pic_id + ".jpg"
            filename.appendChild(doc.createTextNode(pic_name))
            annotation.appendChild(filename)

            sizeimage = doc.createElement("size")
            imagewidth = doc.createElement("width")
            imageheight = doc.createElement("height")
            imagedepth = doc.createElement("depth")

            imagewidth.appendChild(doc.createTextNode("960"))
            imageheight.appendChild(doc.createTextNode("540"))
            imagedepth.appendChild(doc.createTextNode("3"))

            sizeimage.appendChild(imagedepth)
            sizeimage.appendChild(imagewidth)
            sizeimage.appendChild(imageheight)
            annotation.appendChild(sizeimage)

            target_list = child.getchildren()[0]  # 获取target_list
            # print(target_list.tag)
            object = None
            for target in target_list:
                if (target.tag == "target"):
                    # print(target.tag)
                    object = doc.createElement('object')
                    bndbox = doc.createElement("bndbox")

                    for target_child in target:
                        if (target_child.tag == "box"):
                            xmin = doc.createElement("xmin")
                            ymin = doc.createElement("ymin")
                            xmax = doc.createElement("xmax

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;