我正在实施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.您可以在顶层Scale
层之前添加Softmax
层:
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"
}
关于neural-network - Caffe:Softmax与温度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33622333/