Caffe学习(二):Windows训练与测试Caffe mnist

参考以下两篇文章来做训练(任选一):

1. windows下caffe训练mnist数据集https://blog.csdn.net/panhong1992/article/details/84593439

2. Windows caffe (一) MNIST手写体跑起来https://blog.csdn.net/renyhui/article/details/60871888

第1篇文章中只写了训练mnist,可参考第2篇文章多了测试的步骤,即:

模型训练好后,在examples\mnist\mnist_data\ 目录下多了caffemodel模型文件,因此在caffe-master目录下创建test_mnist.bat文件,并运行即可

.\Build\x64\Release\caffe.exe test -model=examples\mnist\lenet_train_test.prototxt -weights=examples\mnist\mnist_data\lenet_iter_10000.caffemodel -iterations=100
pause

注意这里使用到的是lenet_train_test.prototxt文件,因此这里的测试是对训练样本中的验证集数据进行测试。

运行结果如下:

测试单张图片

创建一张28x28, 256位黑底白字的图片,如下,命名为num.bmp, 放到examples/images/路径下

在examples目录下创建python文件test_mnist_num.py,代码如下:

注意这里的网络文件为lenet.prototxt,为真正的测试prototxt文件,即deploy部署文件

import os.path as osp
import caffe

this_dir = osp.dirname(__file__)
model_file = osp.join(this_dir, 'mnist/lenet.prototxt')
pretrained = osp.join(this_dir, 'mnist/mnist_data/lenet_iter_10000.caffemodel')
image_file = osp.join(this_dir, 'images/num.bmp')

input_image = caffe.io.load_image(image_file, color=False)
net = caffe.Classifier(model_file, pretrained)
prediction = net.predict([input_image], oversample=False)
caffe.set_mode_gpu()

print 'predicted_class:', prediction[0].argmax()

运行后,结果如下:

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值