Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. 自己实现的 SoftIoU Loss,用于前景背景的图像分割,相较于 Focal Loss,SoftIoU Loss 的好处是不需要设置 Loss 的参数了,只要关注 Model 就好了
  2.  
  3.  
  4. ```Python
  5. from gluoncv.loss import Loss as gcvLoss
  6.  
  7. class SoftIoULoss(gcvLoss):
  8. def __init__(self, batch_axis=0, weight=None):
  9. super(SoftIoULoss, self).__init__(weight, batch_axis)
  10.  
  11. def hybrid_forward(self, F, pred, target):
  12. pred = F.sigmoid(pred)
  13. smooth = 1
  14. intersection = pred * target
  15. loss = (intersection.sum() + smooth) / (pred.sum() + target.sum() -
  16. intersection.sum() + smooth)
  17. loss = 1 - loss
  18.  
  19. return loss
  20. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement