假如一個bbox坐標為:[35 220 62 293 3]
第一步:將bbox轉換為中心坐標和寬高形式(3種縮放比例進行縮放)
那么onehot:[0 0 0 1 0 0 0 0 0 0 ........],當然還可以平滑
計算bbox的中心坐標和寬高(35+62)/2 = 48.5 (220+293)/2=256.5 寬高為62-35 = 27 293-220=73
所以bbox的寬高中心坐標為(48.5 256.5 27 73)
然后根據縮放比例(8 16 32)進行縮放
縮放后的3組坐標為[[6.0625 32.0625 3.375 9.125][3.03 16.03 1.68 4.56][1.51 8.01 0.84 2.28]]
第二步:anchors中心和寬高獲取
anchors的中心坐標和寬高總共3組每個縮放比例為8 :[[6.5 32.5 1.25 1.625][6.5 32.5 2 3.75][6.5 32.5 4.125 2.875]]
縮放比例為16:[[3.5 16.5 1.875 3.8125][3.5 16.5 3.875 2.8125][3.5 16.5 3.6875 7.4375]]
縮放比例為32:[[1.5 8.5 3.625 2.8125][1.5 8.5 4.875 6.1875][1.5 8.5 11.65625 10.1875]]
其中中心坐標為bbox的取整坐標加0.5,寬高坐標為kmeans聚類出來的
然后bbox的3組坐標分別和anchors的3組坐標計算iou
3組不同比例縮放的bbox對應3組anchors找到iou>0.3的並將網格的左上角坐標標記下來。
label格式為[np.zeros((train_output_sizes[i], train_output_sizes[i], anchor_per_scale,5 + num_classes)) for i in range(3)]
那么label i= [1,2,3]代表3種尺度:
label[i][yind, xind, iou_mask, :] = 0
label[i][yind, xind, iou_mask, 0:4] = bbox_xywh
label[i][yind, xind, iou_mask, 4:5] = 1.0
label[i][yind, xind, iou_mask, 5:] = smooth_onehot
