Key error: Prob pycaffe

491 views
Skip to first unread message

connor amorin

unread,
Jul 13, 2017, 8:05:29 PM7/13/17
to Caffe Users
Hello,

I am trying to use pycaffe on my test set. I am trying to roughly follow the classification notebook, but expanding it to a set rather than just the one image.

Enter cimport sys
import numpy as np
import os.path as osp
import caffe



CLASSES
= 11
num2cls
= ['AMP_Scratch', 'Coat_Defect','Coat_Flake', 'Etch_Pit', 'Mussel', 'Other', 'Pansy', 'Particle', 'Scratch', 'Splatter', 'TBD']

caffe
.set_device(0)
caffe
.set_mode_gpu()
net_def
= '/path/to/prototext'
weights
= '/path/to/weights'

net
= caffe.Net(net_def, weights, caffe.TEST)

num_batches
= 937 #number of files to be tested
output_file
= '/g/g14/amorin1/DamageNet/Models/AlexNet/7.6.2017/pytest.out'

for t in range(num_batches):
     
# next batch
    output
= net.forward()
    label
= net.blobs['label'].data
    output_prob
= output['prob'][0]

   
print 'label'
   
print 'predicted class is:', output_prob.argmax()
   
print 'output label:', num2cls[output_prob.argmax()]


ode here
...

I get this error:

  output_prob = output['prob'].
KeyError: 'prob'

I also get this error before the net is loaded, but the test continues:

W0713 15:40:53.573498 125192 _caffe.cpp:135] DEPRECATION WARNING - deprecated use of Python interface
W0713 15:40:53.573940 125192 _caffe.cpp:136] Use this instead (with the named "weights" parameter):

Not sure if these are related?

Thanks!



shruti sneha

unread,
Jul 17, 2017, 6:25:52 AM7/17/17
to Caffe Users
Hi,
after using net.forward( )
try to use net.blobs['prob'].data[0] for getting the probability value.

Plz let me knw if it helps and correct me if I am wrong :)

Best Regards,
Shruti

C.amo

unread,
Jul 17, 2017, 8:12:28 PM7/17/17
to Caffe Users
So it turns out I was not understanding exactly what net.forward() does.  Output['prob'] does not exist because I  did not have a layer named 'prob'. I had assumed 'prob' was general caffe syntax, but it turns out the format is output['layer name']. It wasn't obvious from the pycaffe examples.

shruti sneha

unread,
Jul 18, 2017, 12:07:50 AM7/18/17
to Caffe Users
So, does this mean, you resolved your problem? Great ..!!

Przemek D

unread,
Jul 19, 2017, 2:17:44 AM7/19/17
to Caffe Users
It is actually output['blob name'] - you should not assume these two will always be equivalent.
Reply all
Reply to author
Forward
0 new messages