问题:在xml转yolo_txt时,代码运行无错,标签(labels)文件为空。
解决方式:classes = ["hat", "person"] #将hat和person 改成自己的类别
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import os
from os import getcwd
sets = ['train', 'val', 'test']
# classes = ["head", "helmet"] # 改成自己的类别
classes = ["hat", "person"] # 改成自己的类别
abs_path = os.getcwd()
print(abs_path)
def convert(size, box):
dw = 1. / (size[0])
dh = 1. / (size[1])
x = (box[0] + box[1]) / 2.0 - 1
y = (box[2] + box[3]) / 2.0 - 1
w = box[1] - box[0]
h = box[3] - box[2]
x = x * dw
w = w * dw
y = y * dh
h = h * dh
return x, y, w, h
def convert_annotation(image_id):
in_file = open('D:/YOLOv5/HelmetDetection/VOC2007/Annotations/%s.xml' % (image_id), encoding