Dice loss

转自:
https://blog.csdn.net/wangdongwei0/article/details/84576044

Dice Loss

首先定义两个轮廓区域的相似程度,用A、B表示两个轮廓区域所包含的点集,定义为:

                                                            DSC(A,B) = 2\left | A\cap B \right |/(\left | A \right | + \left | B \right |)

那么loss为:

可以看出,Dice Loss其实也可以分为两个部分,一个是前景的loss,一个是物体的loss,但是在实现中,我们往往只关心物体的loss,Keras的实现如下:


 
 
  1. def dice_coef(y_true, y_pred, smooth=1):
  2. intersection = K.sum(y_true * y_pred, axis=[ 1, 2, 3])
  3. union = K.sum(y_true, axis=[ 1, 2, 3]) + K.sum(y_pred, axis=[ 1, 2, 3])
  4. return K.mean( ( 2. * intersection + smooth) / (union + smooth), axis= 0)
  5. def dice_coef_loss(y_true, y_pred):
  6. 1 - dice_coef(y_true, y_pred, smooth= 1)

上面的代码只是实现了2分类的dice loss,那么多分类的dice loss又应该是什么样的呢?

注:正确性还没验证。。。


 
 
  1. # y_true and y_pred should be one-hot
  2. # y_true.shape = (None,Width,Height,Channel)
  3. # y_pred.shape = (None,Width,Height,Channel)
  4. def dice_coef(y_true, y_pred, smooth=1):
  5. mean_loss = 0;
  6. for i in range(y_pred.shape( -1)):
  7. intersection = K.sum(y_true[:,:,:,i] * y_pred[:,:,:,i], axis=[ 1, 2, 3])
  8. union = K.sum(y_true[:,:,:,i], axis=[ 1, 2, 3]) + K.sum(y_pred[:,:,:,i], axis=[ 1, 2, 3])
  9. mean_loss += ( 2. * intersection + smooth) / (union + smooth)
  10. return K.mean(mean_loss, axis= 0)
  11. def dice_coef_loss(y_true, y_pred):
  12. 1 - dice_coef(y_true, y_pred, smooth= 1)

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值