Softmax Layer作用是將分類網絡結果概率統計化,常常出現在全連接層後面
CNN分類網絡中,一般來說全連接輸出已經可以結束了,但是全連接層的輸出的數字,有大有小有正有負,人看懂不說,關鍵是訓練時,它無法與groundtruth對應(不在同一量級上),所以用Softmax Layer將其概率統計化,將輸出歸一化爲和爲1的概率值;這樣我們能一眼看懂,關鍵是SoftmaxWithLossLayer也可以計算loss值
首先我們先看一下 SoftmaxParameter
// Message that stores parameters used by SoftmaxLayer, SoftmaxWithLossLayer
message SoftmaxParameter {
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 1 [default = DEFAULT];
// The axis along which to perform the softmax -- may be negative to index
// from the end (e.g., -1 for the last axis).
// Any other axes will be evaluated as independent softmaxes.
optional int32 axis = 2 [default = 1];
}
Softmax Layer在prototxt裏面的書寫:
layers {
name: "prob"
type: “Softmax"
bottom: " fc"
top: "prob"
}
SoftmaxWithLossLayer在prototxt裏面的書寫:
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "prob"
bottom: "label"
top: "loss"
}