machine-learning - Caffe,连接 2 个模型的输出

标签 machine-learning neural-network deep-learning caffe

我有 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
  }
}

Model image

最佳答案

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

关于machine-learning - Caffe,连接 2 个模型的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42594207/

相关文章:

numpy - Keras(Numpy 输入)TypeError : Error converting shape to a TensorShape: int() argument must be a string, 类字节对象或数字,而不是 'tuple'

python - H2O 性能指标 : AUCPR not available?

scala - 理解mllib滑动

音频分割

tensorflow - 如何使用tensorflow对象检测API进行人脸检测

python - 如何让 Keras 在特定 GPU 上训练模型?

python - 如何评估xgboost分类模型稳定性

machine-learning - 如何使用 LSTM 构建语言模型来分配给定句子的出现概率

machine-learning - 在 Accord.Net 中训练神经网络后测试性能不一致/不同/错误

performance - MATLAB 中人工神经网络的回归与性能图之间的差异