More code implementations: https://github.com/Tangzixia/Vehicle-Detection-YOLO-ver/blob/master/yolo_tiny.py
def interpret_output (YOLO, Output): Probs = Np.zeros ((7, 7, 2,)) Class_probs = Np.reshape (output[0:980], (7, 7, ) scales = Np.reshape (output[980:1078], (7, 7, 2)) boxes = Np.reshape (output[1078:], (7, 7, 2, 4)) offset = Np.transpose (Np.reshape (Np.array ([Np.arange (7)] *), (2, 7, 7)), (1, 2, 0)) boxes[:,:,:, 0] + = offset boxes [:,:,:, 1] + = Np.transpose (offset, (1, 0, 2)) boxes[:,:,:, 0:2] = boxes[:,:,:, 0:2]/7.0 boxes[:,:,:, 2] = Np.multiply (boxes[:,:,:, 2], boxes[:,:,:, 2]) boxes[:,:,:, 3] = np.multiply (boxes[:,:,:, 3], boxes[:,:,:, 3]) boxes[:,:,:, 0] *= yolo.w_img boxes[:,:,:, 1] *= yolo.h_img boxes[:,:,:, 2] *= yolo.w_img boxes [:,:,:, 3] *= yolo.h_img for I in range (2):-J in range: probs[:,:, I, j] = Np.multiply (class_probs[:,:, J], scales[:,:, I]) #这里我们得到了7 *7*2 box, which has 98 boxes, each with its own 20-class score, which has 1960 scores, and removes some particularly low scores by setting a threshold value Filter_ Mat_probs = Np.array (proBS >= Yolo.threshold, dtype= ' bool ') #这儿假设我们得到了1160个得分, because they are representations above the dimensions of [7,7,2,20], so now we can use filter_mat_boxes 1160 "
True "scores scored in 7,7,2,20 four dimensions. Filter_mat_boxes = Np.nonzero (filter_mat_probs) boxes_filtered = Boxes[filter_mat_boxes[0], filter_mat_boxes[1], filt ER_MAT_BOXES[2]] #这样将得到1160个得分, that is, the probs_filtered dimension is (1160,) probs_filtered = Probs[filter_mat_probs] #这样将得到每个得分属 In which class, the dimension is (1160,) classes_num_filtered = Np.argmax (Filter_mat_probs, axis=3) [Filter_mat_boxes[0], Filter_mat_bo XES[1], filter_mat_boxes[2]] #对所有的得分进行排序 (default is from small to large order, now we convert to from large to small order) Argsort = Np.array (Np.argsort (probs_filtered )) [:: -1] #然后就可以得到从得分从大到小排列的1160个框 (can be seen as 98 boxes, each box can correspond to a small box of 1~20) boxes_filtered = Boxes_filtered[argsort] #可以得到得 Sorting from large to small order probs_filtered = Probs_filtered[argsort] #调整好对应的类的对应关系 classes_num_filtered = classes_num_filtered[ Argsort] #对于一个框, you and yourself must be iou==1, so you can delete it, and then remove the box that intersects it IOU greater than the threshold to delete the for I in Range (len (boxes_filtered)): If Probs_fi LTered[i] = = 0:continue for j in range (i + 1, len (boxes_filtered)): If IOU (Boxes_filtered[i], Boxes_fi LTERED[J]) > Yolo.iou_threshold:probs_filtered[j] = 0.0 #到最后, the rest of the box corresponds to the NMS processed box Filter_iou = n P.array (probs_filtered > 0.0, dtype= ' bool ') boxes_filtered = Boxes_filtered[filter_iou] probs_filtered = Probs_ Filtered[filter_iou] classes_num_filtered = Classes_num_filtered[filter_iou] result = [] for i in range (len (b oxes_filtered): Result.append ([Yolo.classes[classes_num_filtered[i]], boxes_filtered[i][0], Boxes_fi LTERED[I][1], boxes_filtered[i][2], boxes_filtered[i][3], Probs_filtered[i]]) return result