Skip to content

Commit

Permalink
[Fix] Fix nan loss in RotatedIoULoss when using AmpOptimizer (open-mm…
Browse files Browse the repository at this point in the history
…lab#889)

* [Fix] Fix nan loss in RotatedIoULoss when using AmpOptimizer

* Fix lint
  • Loading branch information
jamiechoi1995 authored Jul 4, 2023
1 parent 4aae1fc commit d50ab76
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions mmrotate/models/losses/rotated_iou_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ def forward(self,
# iou_loss of shape (n,)
assert weight.shape == pred.shape
weight = weight.mean(-1)
loss = self.loss_weight * rotated_iou_loss(
pred,
target,
weight,
mode=self.mode,
eps=self.eps,
reduction=reduction,
avg_factor=avg_factor,
**kwargs)
with torch.cuda.amp.autocast(enabled=False):
loss = self.loss_weight * rotated_iou_loss(
pred,
target,
weight,
mode=self.mode,
eps=self.eps,
reduction=reduction,
avg_factor=avg_factor,
**kwargs)
return loss

0 comments on commit d50ab76

Please sign in to comment.