Reputation: 83157
I trained a neural network using Caffe. I then use it to predict outputs given some new inputs. To do so, I load the trained neural network in pycaffe along with a deploy.prototxt, which specifies the inputs:
name: "IrisNet"
input: "data"
input_dim: 1 # batch size
input_dim: 1
input_dim: 1
input_dim: 300 # number of features
input: "adbeoption"
input_dim: 1 # batch size
input_dim: 1
input_dim: 1
input_dim: 1 # number of features
layer {
name: "ip1"
type: "InnerProduct"
bottom: "data"
top: "ip1"
[...]
I load the neural network using:
my_net = caffe.Net(deploy_prototxt_filename,caffemodel_filename, caffe.TEST)
Since I don't know in advance how many inputs I will have, I would like to be able to change the batch size after I loaded the neural network (i.e. after calling caffe.Net()
). How to do so?
Upvotes: 1
Views: 672
Reputation: 83157
You can use reshape
:
net.blobs['data'].reshape(data_batch_size, 1, 1, data_of_features)
net.blobs['adbeoption'].reshape(adbeoption_batch_size, 1, 1, 1)
Then you can call net.forward()
.
It will modify the batch size on the fly, without having to reload the ANN.
Upvotes: 1