Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions yolox/models/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def forward(self, pred, target):

en = (tl < br).type(tl.type()).prod(dim=1)
area_i = torch.prod(br - tl, 1) * en
iou = (area_i) / (area_p + area_g - area_i + 1e-16)
area_u = area_p + area_g - area_i
iou = (area_i) / (area_u + 1e-16)

if self.loss_type == "iou":
loss = 1 - iou ** 2
Expand All @@ -42,7 +43,7 @@ def forward(self, pred, target):
(pred[:, :2] + pred[:, 2:] / 2), (target[:, :2] + target[:, 2:] / 2)
)
area_c = torch.prod(c_br - c_tl, 1)
giou = iou - (area_c - area_i) / area_c.clamp(1e-16)
giou = iou - (area_c - area_u) / area_c.clamp(1e-16)
loss = 1 - giou.clamp(min=-1.0, max=1.0)

if self.reduction == "mean":
Expand Down Expand Up @@ -77,5 +78,5 @@ def sigmoid_focal_loss(inputs, targets, num_boxes, alpha: float = 0.25, gamma: f
if alpha >= 0:
alpha_t = alpha * targets + (1 - alpha) * (1 - targets)
loss = alpha_t * loss
#return loss.mean(0).sum() / num_boxes
return loss.sum() / num_boxes
# return loss.mean(0).sum() / num_boxes
return loss.sum() / num_boxes