2017-06-06 237 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

相关问题