我正在尝试使用 Caffe C++ classification示例(这里是 code)用手写数字对图像进行分类(我在 MNIST 数据库上训练我的模型),但它总是返回像
这样的概率[0, 0, 0, 1.000, 0, 0, 0, 0, 0] (1.000 can be on different position)
即使图像上没有数字。我觉得应该是这样的
[0.01, 0.043, ... 0.9834, ... ]
此外,例如对于“9”,它总是预测错误的数字。
我在 classification.cpp 中唯一改变的是我一直在使用 CPU
//#ifdef CPU_ONLY
Caffe::set_mode(Caffe::CPU); // <----- always CPU
//#else
// Caffe::set_mode(Caffe::GPU);
//#endif
这就是我的 deploy.prototxt 的样子
name: "LeNet"
layer {
name: "data"
type: "ImageData"
top: "data"
top: "label"
image_data_param {
source: "D:\\caffe-windows\\examples\\mnist\\test\\file_list.txt"
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 20
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 50
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer {
name: "ip1"
type: "InnerProduct"
bottom: "pool2"
top: "ip1"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "ip1"
top: "ip1"
}
layer {
name: "ip2"
type: "InnerProduct"
bottom: "ip1"
top: "ip2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 10
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "loss"
type: "Softmax"
bottom: "ip2"
top: "loss"
}
file_list.txt 是
D:\caffe-windows\examples\mnist\test\test1.jpg 0
而tests1.jpg是这样的
(黑白 28*28 图像保存在 paint 中,我尝试了不同的尺寸但没关系,Preprocces() 无论如何都会调整它的大小)
那么为什么它总是以 100% 的概率预测错误的数字?
(我使用的是 windows 7,VS13)
最佳答案
在您的“ImageData”层中,您应该通过“缩放”将 test1.jpg 数据从 [0, 255] 归一化为 [0, 1],以保持训练和测试之间预处理方式的一致性,如下所示:
image_data_param {
source: "D:\\caffe-windows\\examples\\mnist\\test\\file_list.txt"
scale: 0.00390625
}
关于c++ - Caffe classifocation.cpp 始终返回 100% 概率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38188578/