本文主要是介绍GIOU LOSS pytoch代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
具体请参考:generalized-iou/Detectron.pytorch
主要代码:
x1, y1, x2, y2 = bbox_transform(output, transform_weights)x1g, y1g, x2g, y2g = bbox_transform(target, transform_weights)x2 = torch.max(x1, x2)y2 = torch.max(y1, y2)xkis1 = torch.max(x1, x1g)ykis1 = torch.max(y1, y1g)xkis2 = torch.min(x2, x2g)ykis2 = torch.min(y2, y2g)xc1 = torch.min(x1, x1g)yc1 = torch.min(y1, y1g)xc2 = torch.max(x2, x2g)yc2 = torch.max(y2, y2g)intsctk = torch.zeros(x1.size()).to(output)mask = (ykis2 > ykis1) * (xkis2 > xkis1)intsctk[mask] = (xkis2[mask] - xkis1[mask]) * (ykis2[mask] - ykis1[mask])unionk = (x2 - x1) * (y2 - y1) + (x2g - x1g) * (y2g - y1g) - intsctk + 1e-7iouk = intsctk / unionkarea_c = (xc2 - xc1) * (yc2 - yc1) + 1e-7miouk = iouk - ((area_c - unionk) / area_c)iou_weights = bbox_inside_weights.view(-1, 4).mean(1) * bbox_outside_weights.view(-1, 4).mean(1)iouk = ((1 - iouk) * iou_weights).sum(0) / batch_sizemiouk = ((1 - miouk) * iou_weights).sum(0) / batch_size
这篇关于GIOU LOSS pytoch代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!