[英]How to get probabilties in caffe model
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, 我正在使用Squeezenet,最后几层看起来像这样,我不太确定到底要为我进行哪些更改才能利用概率,
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 : 在python中,您可以执行以下形式的操作:
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 . 为了更深入地了解caffe网络手术的代码段和其他有用功能,我建议使用此链接 。
What you are missing is a "Softmax"
layer that "converts" your predictions into per-class probabilities 您缺少的是一个
"Softmax"
层,该层将您的预测“转换”为每个类别的概率
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) 请注意,您的损失层
"SoftmaxWithLoss"
在内部进行了非常相同的概率计算(理论上,您可能将这些概率作为损失层的第二层,但出于某种原因,我从未设法使其起作用。PR#5828假设使其正常工作)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.