I am using Squeezenet,the final few layers look like this,Im not really sure what exactly to change for me to be able to avail probabilities,
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "pool10"
bottom: "label"
top: "loss"
#include {
# phase: TRAIN
#}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "pool10"
bottom: "label"
top: "accuracy"
#include {
# phase: TEST
#}
}
layer {
name: "accuracy_top5"
type: "Accuracy"
bottom: "pool10"
bottom: "label"
top: "accuracy_top5"
#include {
# phase: TEST
#}
accuracy_param {
top_k: 5
}
}
How do i get probabilities instead of binary outputs? Thanks in advance.
In python you can do something of this form :
caffe.set_mode_gpu()
net = caffe.Net('path/to/deploy.prototxt', 'path/to/mode.caffemodel',caffe.TEST)
for image in images:
im = np.array(caffe.io.load_image(image))
im = np.array(im,dtype=np.float32)
im = im.transpose(2,0,1)
net.blobs['data'].reshape(1,*im.shape)
net.blobs['data'].data[...] = im
net.forward()
print(net.blobs['prob'].data)
For a more in depth understanding of the code snippet and other useful features of caffe network surgery, I recommend this link .
What you are missing is a "Softmax"
layer that "converts" your predictions into per-class probabilities
layer {
name: "prob"
type: "Softmax"
bottom: "pool10"
top: "prob"
}
Note that your loss layer, "SoftmaxWithLoss"
does this very same probability calculation internally (in theory you may get these probabilities as a second top of the loss layer, but for some.e reason I never managed to make it work. PR #5828 suppose to make it work)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.