Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caffe variable batch size

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?

like image 700
dontloo Avatar asked Jul 12 '26 10:07

dontloo


1 Answers

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.

like image 191
Amir Avatar answered Jul 17 '26 23:07

Amir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!