Reputation: 263
After I trained some weights of a CNN, I decide to use the same net architecture to do the prediction.
I set my data batch_size = 64
.
I can properly run the pred_net.forward()
function, and I can get the predicted classes from blobs['prob']
.
There are 20000 samples in my dataset. If I call forward()
function for i
times, I will get 64*i
samples forwarded to the net. So I can not cover the 20000 samples without forwarding some samples twice.
Therefore, I tried the forward_all()
function. But I got an exception without any useful information. I don't know what's wrong.
I expected that forward()
and forward_all()
are similar(but not).
Here are the part of my code and the error message:
pred_net = caffe.Net(pred_net_proto_file, 'kg_trained.caffemodel', caffe.TEST)
pred_net.forward_all()
---------------------------------------------------------------------------
StopIteration Traceback (most recent call last)
<ipython-input-6-cefd35621a35> in <module>()
----> 1 pred_net.forward_all()
/home/microos/Space/caffe-master/python/caffe/pycaffe.pyc in _Net_forward_all(self, blobs, **kwargs)
197 all_outs[out] = np.asarray(all_outs[out])
198 # Discard padding.
--> 199 pad = len(six.next(six.itervalues(all_outs))) - len(six.next(six.itervalues(kwargs)))
200 if pad:
201 for out in all_outs:
StopIteration:
Hopefully, I described things clearly.
Upvotes: 3
Views: 2097
Reputation: 236
you have to pass the data you want to forward to the forward_all() function:
pred_net = caffe.Net(pred_net_proto_file, 'kg_trained.caffemodel', caffe.TEST)
pred_net.forward_all(data=data_samples)
suppose your CNN expects images of the shape (3,224,224) then your data_samples should have the shape (20000,3,224,224)
Upvotes: 2