Caffe可变批量大小

时间:2016-08-17 13:45:06

标签: neural-network caffe

我知道如果我的输入层如下,我的网络将采用维度为(1,1,100,100)的blob。

layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param {
    shape {
      dim: 1
      dim: 1
      dim: 100
      dim: 100
    }
  }
}

如何制作第一个维度(输入批量大小)变量?这样我可以提供不同大小的网络批次吗?

2 个答案:

答案 0 :(得分:3)

您可以在调用forward()方法之前重塑网络。因此,如果您想要一个变量batch_size,您应该每次都重塑一次。这可以在您使用的任何接口(C,python,MATLAB)中完成。

在python中,它是这样的:

net.blobs['data'].reshape(BATCH_SIZE, CHANNELS, HEIGHT, WIDTH)
net.reshape()
net.forward()

提示:我相信net.reshape()是可选的,网络会在执行转发操作之前调用它。

答案 1 :(得分:0)

除了AHA的回答,在c ++中它就像

Blob<float>* input_layer = net_->input_blobs()[0];
input_layer->Reshape(batch_size, input_layer->shape(1), input_layer->shape(2), input_layer->shape(3));
net_->Reshape();