如何在Caffe中重新塑造blob?

8
如何在Caffe中将形状为N x C x H x W的数据块重新塑造为N x 1 x (C*H) x W的形式?
我想创建一个卷积层,其通道之间的权重是相同的。
我想到了一种方法,即将形状为N x C x H x W的底部数据块重新塑造为N x 1 x (C*H) x W的形式,并在其上放置一个卷积层。但我不知道如何重新塑造这个数据块。
请帮我解决这个问题,谢谢。
4个回答

7

正如whjxnyzh所指出的那样,您可以使用"Reshape"层。Caffe在定义输出形状方面非常灵活。
请参阅caffe.protoreshap_param的声明

// 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中的相关信息。


这个也可以通过blob类的方法reshape(const vector<int>& shape)来实现吗?类方法reshape和reshape层有什么区别? - Scott Yang

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、卷积,然后再重新调整回来的需要,这可能会在边缘附近引入跨通道干扰。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接