参考博客:/auto1993/article/details/70941440
在上一篇博客中已经训练好了 mnist 识别手写数字的模型,这篇博客就利用 caffe 的 python 接口对得到的模型进行测试
from PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport caffefrom skimage import ioimgsource = 'F:/python_work/mnist/images/001.png'img = Image.open(imgsource)plt.figure("image")plt.imshow(img)plt.show()modefile = 'F:/caffe-master/examples/mnist/lenet.prototxt'pretrain = 'F:/caffe-master/examples/mnist/lenet_iter_10000.caffemodel'inputImage = caffe.io.load_image(imgsource,color=False)net = caffe.Classifier(modefile,pretrain)prediction = net.predict([inputImage],oversample=False)caffe.set_mode_gpu()print'predicted classes:',prediction[0].argmax()
运行结果