制作数据集主要是为了跑pytorch版本的yolo 超链接
1、用labelimg标注图片,注意要用voc格式生成xml,不要用yolo格式txt
2、使用类似
find ./cafe_0001a_out -name "*rgb.png" -type f -exec mv {} ~/Downloads \;
分离xml文件和jpeg文件,xml放到文件夹annotations下,jpeg文件放到images文件下
2.5 xml转txt
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join
classes = ["plastic","glass","metal","paper","cardboard"]
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(rootpath,xmlname):
xmlpath = rootpath +'Annotations/