【问题标题】:Caffe, joining outputs from 2 modelsCaffe,加入 2 个模型的输出
【发布时间】:2017-07-24 11:14:24
【问题描述】:

我有 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%都达不到。

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

附言。我在创建 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
  }
}

【问题讨论】:

  • @Shai 我知道这是一个问题,但关闭随机播放只是确保我从两个输入中获得相同图片的一种方法。通过改组,它可以在每个输入上返回不同的图像。
  • 随机播放用于生成 lmdbs 的文本文件的行
  • @Shai 我会试试的,谢谢!

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


【解决方案1】:

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

【讨论】:

  • 感谢您的回答。我之前写错了,我在InnerProducts之后使用了Softmax。我不知道的是 Eltwise 层中的参数“coeff”。也许这就是问题所在!我现在就试一试,并在这里写下结果。再次感谢!
  • @AleksanderMonk 我不确定这是否能解决问题。您是否正在训练/微调组合模型?你如何测量准确性?
  • 是的,我正在尝试在其中一个输入上使用普通图像训练组合模型,在第二个输入上训练“锐化”图片。我用准确层更新了我的问题。简而言之,我检查第一个模型的输出精度,检查第二个模型的输出精度和 Eltwise 输出的精度。
  • 我尝试仅在普通图像上运行 blvc_reference_caffenet,经过 15000 次迭代后,精度为 0.001。所以,我的猜测是,不洗牌 caffe 什么都学不到,我必须考虑在 LMDB 中创建 4D 图像(RGB + 我的其他输入)的某种方法。
猜你喜欢
  • 2015-11-09
  • 1970-01-01
  • 1970-01-01
  • 2018-11-18
  • 2023-01-31
  • 1970-01-01
  • 2019-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多