我正在实现Hinton的知识蒸馏论文。第一步是使用更高温度的“笨重模型”的软目标(即每个图像的前向传递并存储具有温度T
的软目标)。
是否有一种方法可以获取Alexnet或googlenet的软目标,但具有不同的温度?
我需要修改softmax函数为pi= exp(zi/T)/sum(exp(zi/T)
。
需要将最终完全连接层的输出除以温度T
。我只需要这个用于前向传递(不用于训练)。
我正在实现Hinton的知识蒸馏论文。第一步是使用更高温度的“笨重模型”的软目标(即每个图像的前向传递并存储具有温度T
的软目标)。
是否有一种方法可以获取Alexnet或googlenet的软目标,但具有不同的温度?
我需要修改softmax函数为pi= exp(zi/T)/sum(exp(zi/T)
。
需要将最终完全连接层的输出除以温度T
。我只需要这个用于前向传递(不用于训练)。
softmax_layer.cpp
的代码来考虑温度T
。你可能需要微调caffe.proto
,以允许解析带有额外参数的Softmax
层。
2. 将该层实现为python层。
3. 如果您只需要前向传递,即“提取特征”,那么您可以简单地输出softmax层之前层的“top”作为特征,并在外部使用温度进行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"
}