Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 自己实现的 SoftIoU Loss,用于前景背景的图像分割,相较于 Focal Loss,SoftIoU Loss 的好处是不需要设置 Loss 的参数了,只要关注 Model 就好了
- ```Python
- from gluoncv.loss import Loss as gcvLoss
- class SoftIoULoss(gcvLoss):
- def __init__(self, batch_axis=0, weight=None):
- super(SoftIoULoss, self).__init__(weight, batch_axis)
- def hybrid_forward(self, F, pred, target):
- pred = F.sigmoid(pred)
- smooth = 1
- intersection = pred * target
- loss = (intersection.sum() + smooth) / (pred.sum() + target.sum() -
- intersection.sum() + smooth)
- loss = 1 - loss
- return loss
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement