目标检测xml标注文件(VOC格式)转为txt标注文件(Yolo格式)
import os.path
import xml.etree.ElementTree as ET
# class_names = ['person', 'rider', 'car', 'truck', 'bus', 'train', 'motorcycle', 'bicycle'] # Cityscapes → Foggy Cityscapes
# class_names = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike',
# 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'] # VOC(clipart)
# class_names = ['bicycle', 'bird', 'cat', 'car', 'dog', 'person'] # watercolor
class_names = ['bicycle', 'bird', 'cat', 'car', 'dog', 'person']
xmlpath = r'D:/ty-code/小论文/数据集/comic2k/xml/' # 原xml路径
txtpath = r'D:/ty-code/小论文/数据集/comic2k/labels/' # 转换后txt文件存放路径
files = []
for root, dirs, files in os.walk(xmlpath):
None
number = len(files)
print(number