参考博客:https://blog.csdn.net/auto1993/article/details/70941440
在上一篇博客中已经训练好了 mnist 识别手写数字的模型,这篇博客就利用 caffe 的 python 接口对得到的模型进行测试
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import caffe
from skimage import io
imgsource = '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()
运行结果