Reputation: 10865
I know if I have the input layer as follows, my network will take in blobs of dimension (1,1,100,100)
.
layer {
name: "data"
type: "Input"
top: "data"
input_param {
shape {
dim: 1
dim: 1
dim: 100
dim: 100
}
}
}
What should I do to make the first dimension (input batch size) variable? so that I can feed in the network batches of different sizes?
Upvotes: 3
Views: 1863
Reputation: 10865
in addition to AHA's answer, in c++ it's like
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();
Upvotes: 0
Reputation: 2415
You can reshape the network before calling the forward()
method. So if you want a variable batch_size, you should reshape the everytime. This can be done in any interface you are using (C, python, MATLAB).
In python, it goes like this:
net.blobs['data'].reshape(BATCH_SIZE, CHANNELS, HEIGHT, WIDTH)
net.reshape()
net.forward()
hint: I believe net.reshape()
is optional and the network calls this before executing the forward action.
Upvotes: 3