yolo3的损失函数讲解
yolov5的损失函数的几点理解
IOU、GIOU、CIOU、DIOU
NMS
非常感谢发布上面文章的博主,帮助太大了。
本当にありがとうございました❕助かりました❕
按照老师提供的论文,将yolov5的NMS中的IOU改为DIOU,修改文件为general.py。虽然改的对不对还不确定。等后天matlab的2w张图的训练集生成结束就试试。生成一个可以用来训练的图片加计算标签平均要6.7s,真顶不住,以后有时间看能不能优化一下代码吧。
iou = box_iou(boxes[i], boxes) > iou_thres # iou matrix
改为
iou = My_Box_DIOU(boxes[i], boxes) > iou_thres # iou matrix
def My_Box_DIOU(box1, box2):
# Returns the IoU of box1 to box2. box1 is 4, box2 is nx4
box2 = box2.T
b1_x1, b1_y1, b1_x2, b1_y2 = box1[0], box1[1], box1[2], box1[3]
b2_x1, b2_y1, b2_x2, b2_y2 = box2[0], box2[1], box2[2], box2[3]
# Intersection area
inter = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \
(torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0)
# Union Area
w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1
w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1
union = w1 * h1 + w2 * h2 - inter
iou = inter / union
cw = torch.max(b1_x2, b2_x2) - torch.min(b1_x1, b2_x1) # convex (smallest enclosing box) width
ch = torch.max(b1_y2, b2_y2) - torch.min(b1_y1, b2_y1) # convex height
c2 = cw ** 2 + ch ** 2 # convex diagonal squared
rho2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 +
(b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4 # center distance squared
return iou - rho2 / c2 # DIoU