1,images,annotations创建
IMAGES:放图片材料的
ANNTATIONS:放labelImg标记的xml文件
2,labels,txt怎么来的
labels :可以手动创建,里面还配置了train,val,test文件夹。可手动(以下代码中没有写)
txt:由一下代码自动生成,前提是images,annotations需要自己去创建
3,xml2txt.py
images,annotations有了之后直接运行一下代码
import xml.etree.ElementTree as ET
import os, cv2
import numpy as np
from os import listdir
from os.path import join
classes = []
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(xmlpath, xmlname):
with open(xmlpath, "r", encoding='utf-8') as in_file:
txtname = xmlname[:-4] + '.txt'
txtfile = os