一、YOLO标签的格式
<object-class> <x> <y> <width> <height>
具体的例子如下:
0 0.412500 0.318981 0.358333 0.636111
x,y是目标的中心坐标,width,height是目标的宽和高。这些坐标是通过归一化的,其中x,width是使用原图的width进行归一化;而y,height是使用原图的height进行归一化。
二、VOC与YOLO之间的格式转换
# size是原图的(w,h)
# box是坐标
def voc_to_yolo(size, box):
dw = 1./size[0]
dh = 1./size[1]
x = (box[0] + box[1])/2.0
y = (box[2] + box[3])/2.0
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 yolo_to_voc(size, box):
x = box[0] * size[0]
w = box[2] * size[0]
y = box[1] * size[1]
h = box[3] * size[1]
xmin = int(x - w/2)
xmax = int(x + w/2)
ymin = int(y - h/2)
ymax = int(y + h/2)
return (xmin, ymin, xmax, ymax)
参考: