Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycaffe Net forward_all() function not working

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.

like image 619
Cuo Show Avatar asked Nov 19 '25 08:11

Cuo Show


1 Answers

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)

like image 158
Erik B. Avatar answered Nov 21 '25 21:11

Erik B.



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!