Caffe:Softmax随温度变化

时间:2015-11-10 03:24:42

标签: neural-network deep-learning caffe conv-neural-network softmax

我正致力于实施Hinton的知识蒸馏paper。第一步是存储具有更高温度的“笨重模型”的软目标(即,我不需要训练网络,只需要对每个图像进行前向传递并存储温度为{{1的软目标) }})。
有没有办法可以获得Alexnet或googlenet软目标的输出,但温度不同? 我需要使用T修改soft-max 需要将最终完全连接层的输出除以温度pi= exp(zi/T)/sum(exp(zi/T)。我只需要这个用于前进传球(不用于训练)。

1 个答案:

答案 0 :(得分:2)

我相信有三种方法可以解决这个问题

1。使用温度参数实现您自己的Softmax图层。修改softmax_layer.cpp的代码以考虑“温度”T应该非常简单。您可能还需要调整caffe.proto以允许使用额外参数解析Softmax图层。

2。将图层实施为python layer

3。如果您只需要正向传递,即“提取功能”,那么您可以简单地输出之前之前的作为功能分层,并在温度高于外面的温度下进行softmax。

4. 您可以在热门Softmax图层前添加Scale图层:

layer {
  type: "Scale"
  name: "temperature"
  bottom: "zi"
  top: "zi/T"
  scale_param { 
    filler: { type: 'constant' value: 1/T }  # replace "1/T" with the actual value of 1/T.
  }
  param { lr_mult: 0 decay_mult: 0 } # make sure temperature is fixed
}
layer {
  type: "Softmax"
  name: "prob"
  bottom: "zi/T"
  top: "pi"
}