如何在我自己的数据集图像上测试mnist

时间:2015-04-15 19:11:20

标签: python opencv neural-network deep-learning caffe

我试图使用我自己的数字图像数据集来测试mnist 我为此写了一个python脚本,但是它给出了一个错误。错误是代码的第16行。实际上我无法发送图像进行测试。给我一些建议。提前谢谢。

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 个答案:

答案 0 :(得分:1)

为什么不使用python包装器类Classifier

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

我不是百分百肯定,但我认为LeNeT模型期望灰度图像,您可能需要阅读图像

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

答案 1 :(得分: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

这段代码对我有用,输出就是这样:

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