神经网络 – Caffe:Softmax随温度变化

我正在努力实施Hinton的知识蒸馏
paper.第一步是存储具有更高温度的“笨重模型”的软目标(即我不需要训练网络,只需要对每个图像进行前向传递和存储温度为T的软目标.

有没有办法可以获得Alexnet或googlenet软目标的输出,但温度不同?

我需要用pi = exp(zi / T)/ sum(exp(zi / T))修改soft-max.

需要将最终完全连接层的输出除以温度T.我只需要这个用于正向传递(不用于训练). 最佳答案 我相信有三种方法可以解决这个问题

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

2.将图层实现为python layer.

3.如果您只需要一个正向通道,即“提取特征”,那么您可以简单地在softmax层之前输出图层的“顶部”,并在温度超出caffe的情况下执行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"
}
点赞