Caffe classifocation.cpp 总是 returns 100% 概率

Caffe classifocation.cpp always returns 100% probability

我正在尝试使用 Caffe c++ classification example (here is the code) 对带有手写数字的图像进行分类(我在 MNIST 数据库上训练我的模型),但它总是 returns 概率

[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()无论如何都会调整它的大小)

为了训练网络,我使用 this tutorial, here is prototxt

那么为什么它总是以 100% 的概率预测错误的数字?

(我正在使用 windows 7,VS13)

在你的 "ImageData" 层,你应该通过 "scale" 将你的 test1.jpg 数据从 [0, 255] 归一化到 [0, 1] 以保持预处理方式的一致性训练和测试如下:

image_data_param {
    source: "D:\caffe-windows\examples\mnist\test\file_list.txt"
    scale: 0.00390625
  }