Convierta cada clase de la clase en su clase import os import xml.etree.ElementTree como ET classid = ('class1': 0, 'class2': 1, 'class3': 2, 'class4': 3, 'class5': 4, 'class6': 5, 'class7': 6} #Lista de categorías, mantenga el orden en el archivo de configuración de entrenamiento todo el tiempo annotation = '/ data /' #xml file savepath = '/ data / labels /' #The txt escrito se coloca en el tren y val debajo de las etiquetas para xmlfile in ('train /', 'val /'): file = os.listdir (annotation + xmlfile) for i in file: infile = annotation + xmlfile + i outfile = open (savepath + xmlfile + i [: - 4] + '. txt', 'w') árbol = ET.parse (infile) raíz = árbol.getroot () tamaño = raíz.find ('tamaño') w_image = float ( size.find ('ancho '). texto) h_image = float (size.find (' altura '). texto) para obj en root.iter ('objeto'): classname = obj.find ('name'). text cls_id = classid [classname] xmlbox = obj.find ('bndbox') xmin = float (xmlbox.find ('xmin ') .text) xmax = float (xmlbox.find (' xmax '). text) ymin = float (xmlbox.find (' ymin '). text) ymax = float (xmlbox.find (' ymax '). text) x_center = ((xmin + xmax) / 2-1) / w_image y_center = ((ymin + ymax) / 2-1) / h_image w = (xmax-xmin) / w_image h = ( ymax-ymin) / h_image archivo de salida . write (str (cls_id) + "" + str (x_center) + "" + str (y_center) + "" + str (w) + "" + str (h) + '\ n') archivo de salida.cerrar()
Convertir el conjunto de datos de voc a txt
Supongo que te gusta
Origin blog.csdn.net/qq_16792139/article/details/113939967
Recomendado
Clasificación