Caffe classifocation.cpp总是返回100%的概率

时间:2016-07-04 15:55:13

标签: c++ neural-network deep-learning caffe conv-neural-network

我尝试使用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就是这样的

enter image description here

(黑色和白色28 * 28图像保存在绘画中,我尝试过不同的尺寸,但这并不重要,Preprocces()无论如何调整大小)

要训练网络我使用this教程,这里是prototxt

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

(我使用的是Windows 7,VS13)

1 个答案:

答案 0 :(得分:1)

在你的&#34; ImageData&#34;图层,你应该将你的test1.jpg数据从[0,255]标准化为[0,1] by&#34; scale&#34;在训练和测试之间保持预处理方式的一致性,如下所示:

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