一、IOU函数
def IOU(box1, box2): #box2 = [x1,y1,h1,w1] #box2 = [x2,y2,h2,w2] x1,y1,h1,w1 = box1 x2,y2,h2,w2 = box2 # 用四个角坐标计算比较方便 left1 = x1 - w1/2 right1 = x1 + w1/2 top1 = y1 - h1/2 bottom2 = y1 + h1/2 left2 = x2 - w2/2 right2 = x2 + w2/2 top2 = y2 - h2/2 bottom2 = y2 + h2/2 # 相交部分的四个角坐标 left = max(left1, left2) top = max(top1,top2) right = min(right1, right2) bottom = min(bottom1, bottom2) #相交部分的面积 inter = max(0, right - left) * max(0, bottom - top) area1 = h1 * w1 area2 = h2 * w2 union = area1 + area2 - inter iou = inter / union return iou
二、Softmax和Cross Entropy