2017-03-04 30 views
1

我有兩種不同的模型,比方說NM1和NM2。Caffe,加入來自2個模型的輸出

所以,我正在尋找的東西,就像下面的例子。

假設我們有一張狗的照片。

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個向量,我想添加它們。在這裏我使用了Eltwise層。

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

加入NM1之前準確度爲〜70%,NM2〜10%。

加入後精度甚至不能達到1%。

因此,我的結論是,我明白了一些錯誤,如果有人能向我解釋我錯在哪裏,我將不勝感激。

PS。我在創建lmdb時確實關閉了洗牌程序。

UPDATE

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

+1

[**不要關閉SHIPPING OFF **](http://stackoverflow.com/a/37659171/1714410)。 – Shai

+0

@Shai我明白這是一個問題,但是隻有一種方法可以確保我從兩個輸入中獲得相同的圖片。 隨着洗牌,它可能會在每個輸入上返回不同的圖像。 –

+1

洗牌用於生成lmdbs的文本文件的行 – Shai

回答

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 
    } 
} 
+0

謝謝你的回答。我以前寫錯了,我在InnerProducts之後使用了Softmax。我不知道的是Eltwise層的論點「coeff」。也許這是問題!我現在試試看,並在這裏寫結果。再次感謝! –

+1

@AleksanderMonk我不確定這會做到這一點。你在訓練/訓練組合模型嗎?你如何衡量準確性? – Shai

+0

是的,我試圖訓練其中一個輸入上的正常圖像和第二個輸入上的「銳化」圖像的組合模型。 我用精確度層更新了我的問題。 簡而言之,我檢查第一個模型輸出的準確性,檢查第二個模型輸出的準確性並檢查Eltwise輸出的準確性。 –