2017-06-06 235 views
1

我在Caffe中有一個網絡,它接受多個圖像輸入(可能具有不同的維度)並將它們用作網絡初始部分的單獨blob。Caffe deploy.prototxt具有不同維度的多個輸入

對於培訓階段,我通過創建HDF5數據庫來實現這一點,如文檔中建議的那樣。

但是,對於部署階段,我需要用訓練階段用輸入層替換數據層,並指定輸入blob的維度。

對於單個blob,這是通過input_param的shape屬性完成的。在這種情況下,我怎麼能做到這一點,我有多個blob,可能有不同的尺寸?

謝謝。

回答

1

如果您在caffe.proto仔細觀察你會發現inputinput_shaperepeated屬性:這意味着你可以有幾個

// DEPRECATED. See InputParameter. The input blobs to the network. 
repeated string input = 3; 
// DEPRECATED. See InputParameter. The shape of the input blobs. 
repeated BlobShape input_shape = 8; 

name: "AnAmazingNetWithMultipleInputs_ThankYouShai_IwillForeverBeInYourDebt" 
input: "first_input_1x3x127x127" 
input_shape { dim: 1 dim: 3 dim: 127 dim: 127 } 
input: "second_input_2x4x224x224" 
input_shape { dim: 2 dim: 4 dim: 224 dim: 224 } 
# I hope you can take it from here ;) 

如果您在的相關部分看得更近,你會注意到這種形式的「輸入形狀聲明」是DEPRECATED。
一個更好的辦法是使用"Input"層:

layer { 
    type: "Input" 
    name: "one_input_layer" 
    top: "first_input_1x3x127x127" 
    shape { dim: 1 dim: 3 dim: 127 dim: 127 } 
    top: "second_input_2x4x224x224" 
    shape { dim: 2 dim: 4 dim: 224 dim: 224 } 
} 

你也可以有不同的"Input"層對於每個輸入,如果你發現它更容易理解/閱讀。

+0

謝謝!我應該想到使用多個輸入層!一個疑問:如果我反覆使用top和shape,每個top之後都必須有一個形狀?它如何建立映射? – GoodDeeds

+0

我想按出場順序 – Shai

+0

謝謝@Shai,那工作。但是,似乎有一個小錯誤:我認爲shape是input_param的一個屬性,而不是直接輸入層。當我嘗試在第二個示例中使用它時出現錯誤,該錯誤通過使用input_param進行了糾正。 – GoodDeeds

相關問題