Caffe,合并两个模型的输出

我有两个不同的模型,假设是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  }}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注