Caffe,加入 2 个模型的输出

Caffe, joining outputs from 2 models

我有 2 个不同的型号,比如说 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 之后)结尾,它给了我 2 个概率向量。

下一步,我有这 2 个向量,我想将它们相加。这里我使用了 Eltwise 层。

layer {
  name: "eltwise-sum"
  type: "Eltwise"
  bottom: "fc8"
  bottom: "fc8N"
  top: "out"
  eltwise_param { operation: SUM }
}

在加入 NM1 之前,准确率约为 70%,而 NM2 约为 10%。

加入后精度连1%都达不到。

因此,我的结论是我理解错了,如果有人能向我解释我错在哪里,我将不胜感激。

PS。我在创建 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 alone
layer {
  name: "accuracyPINorm"
  type: "Accuracy"
  bottom: "fc8L"
  bottom: "label"
  top: "accuracyPiNorm"
  include {
    phase: TEST
  }
}

#accur for norm images alone
layer {
  name: "accuracyIMGNorm"
  type: "Accuracy"
  bottom: "fc8NL"
  bottom: "labelN"
  top: "accuracyIMGNorm"
  include {
    phase: TEST
  }
}

#accur for them together
layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "out"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}

如果您想添加(按元素)概率,您需要在 "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"
}
# Joining the probabilites
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
  }
}