0
votes

I'm trying to use Caffe c++ classification example (here is the code) to classify image with handwritten digit (I train my model on MNIST database), but it always returns probabilities like

[0, 0, 0, 1.000, 0, 0, 0, 0, 0]  (1.000 can be on different position)

even if image has no number on it. I think it should be something like

[0.01, 0.043, ... 0.9834, ... ]

Also, for example for '9', it's always predicts wrong number.
The only one thing I change in classification.cpp is that I'm always using CPU

//#ifdef CPU_ONLY    
  Caffe::set_mode(Caffe::CPU); // <----- always CPU
//#else
//  Caffe::set_mode(Caffe::GPU);
//#endif

This is how my deploy.prototxt looks like

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 is

D:\caffe-windows\examples\mnist\test\test1.jpg 0

And tests1.jpg is something like this

enter image description here

(black&white 28*28 image saved in paint, I have tried different sizes but it doesn't matter, Preprocces() resizes it anyway)

To train network I use this tutorial, here is prototxt

So why it predicts wrong digits and alway with 100% probability?

(I'm using windows 7, VS13)

1

1 Answers

1
votes

In your "ImageData" layer, you should normalize your test1.jpg data from [0, 255] to [0, 1] by "scale" to keep the consistency of preprocess manner between training and test like the following:

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