Focal Loss介绍

从交叉熵讲,

L o s s = L ( y , p ^ ) = − y l o g ( p ^ ) − ( 1 − y ) l o g ( 1 − p ^ ) Loss = L(y, \hat{p})=-ylog(\hat{p})-(1-y)log(1-\hat{p}) Loss=L(y,p^)=ylog(p^)(1y)log(1p^)

以二分类问题为例,

L = 1 N ( ∑ y i = 1 m − l o g ( p ^ ) + ∑ y i = 0 n − l o g ( 1 − p ^ ) ) L=\frac{1}{N}(\sum_{y_i =1}^m -log(\hat{p})+\sum_{y_i=0}^{n}-log(1-\hat{p})) L=N1(yi=1mlog(p^)+yi=0nlog(1p^))

正负样本个数不均,导致训练反馈偏重于样本多的类别。

采用加权,平衡交叉熵

L = 1 N ( ∑ y i = 1 m − α l o g ( p ^ ) + ∑ y i = 0 n − ( 1 − α ) l o g ( 1 − p ^ ) ) L=\frac{1}{N}(\sum_{y_i =1}^m -\alpha log(\hat{p})+\sum_{y_i=0}^{n}-(1-\alpha)log(1-\hat{p})) L=N1(yi=1mαlog(p^)+yi=0n(1α)log(1p^))

α 1 − α = n m \frac {\alpha}{1-\alpha} = \frac {n}{m} 1αα=mn

Focal Loss

L f l = { − ( 1 − p ^ ) γ l o g ( p ^ ) i f y = 1 − p ^ γ l o g ( 1 − p ^ ) i f y = 0 L_{fl} = \begin{cases} -(1-\hat{p})^\gamma log(\hat{p}) &if&y=1 \\ -\hat{p}^\gamma log(1-\hat{p}) & if & y=0 \end{cases} Lfl={(1p^)γlog(p^)p^γlog(1p^)ifify=1y=0
或写成
p t = { p ^ i f y = 1 1 − p ^ o t h e r w i s e L f l = − ( 1 − p t ) γ l o g ( p t ) p_t=\begin{cases} \hat{p} & if & y=1 \\ 1-\hat{p} & otherwise \end{cases} \\ L_{fl}=-(1-p_t)^\gamma log(p_t) pt={p^1p^ifotherwisey=1Lfl=(1pt)γlog(pt)

Focal loss从分类难易程度加权loss,使得loss聚焦于难分样本。

样本少的类别较难分类,Focal loss有助于提高样本少类别的准确率;但难分样本不局限于样本数少的类别。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值