如何重塑Caffe中的blob?

时间:2015-01-22 14:08:54

标签: neural-network reshape deep-learning caffe

如何在Caffe中将形状N x C x H x W的blob重塑为N x 1 x (C*H) x W

我想制作一个卷积层,其权重在通道之间是相同的。

我提出的一种方法是将形状N x C x H x W的底部形状重塑为N x 1 x (C*H) x W并在其上放置卷积层。但我只是不知道如何重塑一个blob。

请帮帮我,谢谢。

4 个答案:

答案 0 :(得分:7)

正如whjxnyzh指出的那样,您可以使用"Reshape"图层。 Caffe在允许您定义输出形状方面非常灵活 见the declaration of reshap_param in caffe.proto`

// Specify the output dimensions. If some of the dimensions are set to 0,
// the corresponding dimension from the bottom layer is used (unchanged).
// Exactly one dimension may be set to -1, in which case its value is
// inferred from the count of the bottom blob and the remaining dimensions.

在你的情况下,我猜你会有一个这样的层:

layer {
  name: "my_reshape"
  type: "Reshape"
  bottom: "in"
  top: "reshaped_in"
  reshape_param { shape: {dim: 0 dim: 1 dim: -1 dim: 0 } }
}

另见caffe.help

答案 1 :(得分:2)

答案 2 :(得分:2)

如果我理解你的最终目标,Caffe的卷积层已经可以使用常见/共享过滤器进行多输入输出卷积,例如:

layer {
  name:   "conv"
  type:   "Convolution"
  bottom: "in1"
  bottom: "in2"
  bottom: "in3"
  top:    "out1"
  top:    "out2"
  top:    "out3"
  convolution_param {
    num_output : 10  #the same 10 filters for all 3 inputs
    kernel_size: 3        
  }
}

假设您已经分割了所有流(切片图层可以执行此操作),最后您可以根据需要将它们合并为concat或eltwise图层。

避免重塑blob,卷积,然后重新整形,这可能会在边缘附近引入跨通道干扰。

答案 3 :(得分:0)

不确定这是否完全符合您的规格,但Caffe确实有平整层。 blob从n * c * h * w变为n *(c h w)* 1 * 1.

请参阅http://caffe.berkeleyvision.org/tutorial/layers.html