21天实战caffe-第三天-将自己的手写体图片进行测试

跟着网上的步骤一步步来做的最后成功了,但是识别精度还是不够好

1.首先是制作自己的手写体图片,必须要像素为28×28的单通道黑白相片(opencv可以制作,电脑没装,所以可以在windows的画图软件制作)

具体过程如下

2.生成deploy.prototxt 文件与训练时的lenet_train_test.prototxt文件类似,前者实测时用的,后者是训练时用的网络配置文件

所以我们可以通过复制重命名的方式制作一个deploy.prototxt文件存放在后者文件的位置

内容如下:

name: "LeNet"  
 
   
layer {  
  name:"data"  
 type: "Input"  
 top: "data"  
 input_param { shape: { dim: 1 dim: 1 dim: 28 dim: 28 } }  
}  
   
  
layer {  
  name:"conv1"  
 type: "Convolution"  
 bottom: "data"  
 top: "conv1"  
 convolution_param {  
   num_output: 20  
   kernel_size: 5  
   stride: 1  
   weight_filler {  
     type: "xavier"  
   }  
 }  
}  
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"  
 convolution_param {  
   num_output: 50  
   kernel_size: 5  
   stride: 1  
   weight_filler {  
     type: "xavier"  
   }  
 }  
}  
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"  
 inner_product_param {  
   num_output: 500  
   weight_filler {  
     type: "xavier"  
   }  
 }  
}  
layer {  
  name:"relu1"  
 type: "ReLU"  
 bottom: "ip1"  
 top: "ip1"  
}  
layer {  
  name:"ip2"  
 type: "InnerProduct"  
 bottom: "ip1"  
 top: "ip2"  
 inner_product_param {  
   num_output: 10  
   weight_filler {  
     type: "xavier"  
   }  
 }  
}  
   
 
layer {  
  name:"prob"  
 type: "Softmax"  
 bottom: "ip2"  
 top: "prob"  
}  

3。生成labels.txt标签文件,放在当前目录下,命名为synset_words.txt,内容为

0

1

2

3

4

5

6

7

8

9

4。使用caffe提供的计算均值文件compute_image_mean.cpp来生成mean.binaryproto二进制均值文件

指令如下sudo build/tools/compute_image_mean examples/mnist/mnist_train_lmdb examples/mnist/mean.binaryproto

5。使用caffe自带的分类器classification.bin

6.开始测试

在caffe根目录下输入下面指令

./build/examples/cpp_classification/classification.bin examples/mnist/deploy.prototxt examples/mnist/lenet_iter_10000.caffemodel examples/mnist/mean.binaryproto examples/mnist/synset_words.txt examples/images/3.jpg  
结果如下

哈哈这是错误结果,因为我的10000次模型可能被修改过,反正模型是有问题的,所以换了5000的模型,结果成功了,但是分类并不准确

我查看了一下两个模型的文件果然时间都不一样,但的确是同一天训练好的模型,所以问了一下浩哥,说这个模型训练时间不长让我重新训练

重新训练好了之后,模型精度虽然没变,5000的精度应该变了,因为同一张图片这次它识别成功了

好的,目前为止其实跑模型测试我差不多可以了,要更加努力又弄懂原理了,bye

猜你喜欢

转载自www.cnblogs.com/stt-ac/p/10578603.html
今日推荐