I have the MNIST model trained after 10000 iterations, showing 99% accuracy, and I am attempting to test it on new single image. Following the steps
here I have modified the network to deploy it, full prototxt can be found here:
https://pastebin.com/fJr0Fij0Using a prediction routine found elsewhere, the model is unable to reliably predict my new image
import caffe
import numpy as np
import matplotlib.pylab as plt
caffe.set_mode_cpu()
MODEL_FILE = 'lenet_deploy.prototxt'
PRETRAINED = 'lenet_iter_10000.caffemodel'
net = caffe.Classifier(MODEL_FILE, PRETRAINED,
raw_scale=1,
image_dims=(28, 28))
def caffe_predict(path):
input_image = caffe.io.load_image(path)
input_image = input_image[:,:,0]
input_image = input_image.reshape(28,28,1)
print path
prediction = net.predict([input_image])
print prediction
print "----------"
#print 'prediction shape:', prediction[0].shape
print 'predicted class:', prediction[0].argmax()
proba = prediction[0][prediction[0].argmax()]
ind = prediction[0].argsort()[-5:][::-1] # top-5 predictions
return prediction[0].argmax(), proba, ind
prediction, prob, ind = caffe_predict('test.png')