2

I'm trying to test mnist using my own dataset of digits images.
I wrote a python script for that but it is giving an error. error is in line no 16 of code. Actually i'm not able to send image for test. give me some suggestions. thanks in advance.

import numpy as np
import sys
import caffe
import matplotlib.pyplot as plt
import os

caffe_root = '../caffe-master/'
MODEL_FILE = './examples/mnist/lenet.prototxt'
PRETRAINED = './examples/mnist/lenet_iter_10000.caffemodel'
IMAGE_FILE = '/home/hemant/OpenCVProject/grey/img001-00001.png'#image path

input_image = caffe.io.load_image(IMAGE_FILE)

net = caffe.Net(MODEL_FILE, PRETRAINED,caffe.TEST)
caffe.set_mode_cpu()
out = net.forward([input_image])
print out['prob']

2 Answers 2

1

Why don't you use the python wrapper class Classifier?

net = caffe.Classifier( MODEL_FILE, PRETRAINED )
net.predict( [input_image], oversmaple=False )

I'm not 100% sure, but I think LeNeT model expect gray scale image, you might need to read the image

input_image = caffe.io.load_image(IMAGE_FILE, color=False)
1
import caffe
import os

model_file = '../examples/mnist/lenet.prototxt'
pretrained_file = '../examples/mnist/lenet_iter_10000.caffemodel'
net = caffe.Classifier(model_file, pretrained_file, image_dims=(28, 28), raw_scale=255)
score = net.predict([caffe.io.load_image('img/1.bmp', color=False)], oversample=False)
print score

This code work for me, the output is like that:

...
[[ 0.  0.  1.  0.  0.  0.  0.  0.  0.  0.]]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.