你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
xmyqsh
赞同来自: caffe 、李士林 、Jinlong_Xu 、hgzry812
要回复问题请先登录或注册
1 个回复
xmyqsh
赞同来自: caffe 、李士林 、Jinlong_Xu 、hgzry812
详见Deep Learning P221 6.5.9 Differentiation outside the Deep Learning Community
For example, suppose we have variables p1,p2,...,pn representing probabilities and variables z1 , z2 , . . . , zn representing unnormalized log probabilities. Suppose
...
construct a cross-entropy loss J = − sum( pi log qi). A human
mathematician can observe that the derivative of J with respect to zi takes a very
simple form: qi − pi .
知道这个trick之后 红框的表达式就不难理解了
bottom_diff[i * dim + label_value * inner_num + j] -= 1 前面还有一句 caffe_copy(prob_.count(), prob_data, bottom_diff);
首先向bottom_diff拷入prob_data, 也就是softmax输出的qi
dim : 表示一个num/batch里一个样本的大小,为 channel * Height * Width
inner_num:表示一个特征图/channel/一个label的大小,为Height * Width,这里就是1*1了
label_val = label[i * inner_num_ + j] 就是 p[label_val] = 1 (只有一个) p[others_label_val] = 0
i * dim + label_value * inner_num + j 就是一个样本里,对应label_val的那个channel的index
对这个index执行 q[index] -= p[label_val]
对这个样本里的其它channel的index默认执行q[index] -= p[other_label_val]