Caffe Loss层 - HingelossLayer

30 篇文章 5 订阅
17 篇文章 0 订阅

HingelossLayer

计算 one-of-many 分类任务的 hinge loss.

Hinge Loss 概念

定义为:
E(z)=max(0,1z) E ( z ) = m a x ( 0 , 1 − z )

常用在SVM的最大化间隔分类中.

对于期望输出 t=+1,1 t = + 1 , − 1 和分类器分 y y , 预测值y的 hinge loss 为:
l(y)=max(0,1ty) l ( y ) = m a x ( 0 , 1 − t ∗ y )
这里, y y 应该是分类器决策函数的原是输出,而不是预测的最终类别结果.
例如,
线性SVMs,y=wx+b,其中 (w,b) ( w , b ) 是超平面的参数, x x 为待分类的点.
t y y 符号相同(即y预测到正确的类别)和 |y|>=1 | y | >= 1 时, hinge loss: l(y)=0 l ( y ) = 0
t t y 符号相反时,hinge loss l(y) l ( y ) 则随着 y y 的增加而线性增加(one-side error).

这里写图片描述

t=1时,针对变量 y y ,其hinge loss(蓝色线) vs. zero-one loss(青色,misclassification).
Note that the hinge loss penalizes predictions y < 1, corresponding to the notion of a margin in a support vector machine(SVM).

Caffe Layer 参数

  • HingeLossLayer 参数:
  • bottom - 输入 Blob 向量(长度为2)
    • a. (NCHW) 大小的预测值 t t ,其各值表示 K=CHW类中的每一个类别的预测分数. 在SVM中, t t 是 D-维特征XRD×K 和学习超平面参数 WRD×K W ∈ R D × K 作为输入,进行内积计算 XTW X T W 得到的结果,故 HingeLossLayer 采用 InnerProductLayer(num_output=D)的预测值作为输入,不需要再学习参数即其它loss计算,即等价于线性SVM(一个全连接层加上一个Hingeloss相当于一个线性SVM).

      • b. (N111) ( N ∗ 1 ∗ 1 ∗ 1 ) 大小的 labels t t ,其值为整数,ln=[0,1,2,...,K1],分别表示所对应的 K K 个类别中正确的类别标签.
    • top - 输出 Blob 向量(长度为1)
      • (1111),计算得到的 hinge loss:
        E=1NNn=1Kk=1[max(0,1σ(ln=k)tnk)]p E = 1 N ∑ n = 1 N ∑ k = 1 K [ m a x ( 0 , 1 − σ ( l n = k ) ∗ t n k ) ] p
        • Lp L p 范数, p=1 p = 1 , L1 范数; p=2 p = 2 , L2 范数,类似于 L2-SVM;
        • if condition c o n d i t i o n σ(condition)=1 σ ( c o n d i t i o n ) = 1 ;otherwise, σ(condition)=1 σ ( c o n d i t i o n ) = − 1 .
      • Caffe prototxt定义

        ......
        layer {
          name: "fc8voc"
          type: "InnerProduct"
          bottom: "fc7"
          top: "fc8voc"
          param {
            lr_mult: 10
            decay_mult: 1
          }
          param {
            lr_mult: 2
            decay_mult: 0
          }
          inner_product_param {
            num_output: 20
            weight_filler {
              type: "gaussian"
              std: 0.01
            }
            bias_filler {
              type: "constant"
              value: 0
            }
          }
        }
        
        layer {
          name: "loss"
          type: "HingeLossMultiLabel"
          bottom: "fc8voc"
          bottom: "label"
          top: "loss"
        }

        Reference

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值