我有两个不同的模型,假设是NM1和NM2。
所以,我想要的是类似于下面的例子那样工作的东西。
假设我们有一张狗的图片。
NM1预测图片上是一只猫,概率为0.52,而预测是一只狗的概率为0.48。NM2预测是一只狗的概率为0.6,而预测是一只猫的概率为0.4。
NM1 – 将会预测错误 NM2 – 将会预测正确
NM1 + NM2 – 连接后将会预测正确(因为0.48 + 0.6 > 0.52 + 0.4)
因此,每个模型最后都使用InnerProducts(在Softmax之后),这给我提供了两个概率向量。
下一步,我有这两个向量,我想把它们加起来。这里我使用了Eltwise层。
layer { name: "eltwise-sum" type: "Eltwise" bottom: "fc8" bottom: "fc8N" top: "out" eltwise_param { operation: SUM }}
在合并之前,NM1的准确率约为70%,NM2约为10%。
合并后,准确率甚至达不到1%。
因此,我的结论是我理解上有些错误,如果有人能向我解释我错在哪里,我将不胜感激。
附注:我在创建lmdb时关闭了shuffle功能。
更新
layer { name: "eltwise-sum" type: "Eltwise" bottom: "fc8L" bottom: "fc8NL" top: "out" eltwise_param { operation: SUM coeff: 0.5 coeff: 0.5 }}#accur for PI alonelayer { name: "accuracyPINorm" type: "Accuracy" bottom: "fc8L" bottom: "label" top: "accuracyPiNorm" include { phase: TEST }}#accur for norm images alonelayer { name: "accuracyIMGNorm" type: "Accuracy" bottom: "fc8NL" bottom: "labelN" top: "accuracyIMGNorm" include { phase: TEST }}#accur for them togetherlayer { name: "accuracy" type: "Accuracy" bottom: "out" bottom: "label" top: "accuracy" include { phase: TEST }}
回答:
如果你想对概率进行元素-wise的加法,你需要在"Softmax"
层之后进行加法,而不是在"InnerProduct"
层之后。你应该有类似下面的配置:
layer { type: "InnerProduct" name: "fc8" top: "fc8" # ... }layer { type: "Softmax" name: "prob_nm1" top: "prob_nm1" bottom: "fc8"}layer { type: "InnerProduct" name: "fc8N" top: "fc8N" # ... }layer { type: "Softmax" name: "prob_nm2" top: "prob_nm2" bottom: "fc8N"}# 合并概率layer { type: "Eltwise" name: "prob_sum" bottom: "prob_nm1" bottom: "prob_nm2" top: "prob_sum" eltwise_param { operation: SUM coeff: 0.5 coeff: 0.5 }}