我已经使用caffe训练了CIFAR QUICK,但是当我使用python包装器测试cifar10_quick_iter_5000.caffemodel.h5时,我的准确度大约为52-54%,而应该是75%。我不明白为什么我的准确度如此之低,因为当我测试Lenet MNIST时,我会根据caffe网站上的MNIST示例获得预期的准确度。为了验证我的方法是对还是错,我已经尝试了来自Clasificador_Cifar-10的cifar训练模型文件,我得到了68%的准确率。
如果我在测试模型时遗失了某些内容,请告诉我。
import sys
import caffe
import cv2
import Image
import matplotlib
import numpy as np
import lmdb
caffe_root = '/home/fred/CIFAR_QUICK/caffe'
MODEL_FILE = '/home/fred/CIFAR_QUICK/caffe/examples/cifar10/cifar10.prototxt'
PRETRAINED = '/home/fred/CIFAR_QUICK/caffe/examples/cifar10/cifar10_60000.caffemodel.h5'
net = caffe.Net(MODEL_FILE, PRETRAINED,caffe.TEST)
caffe.set_mode_cpu()
db_path = '/home/fred/CIFAR_QUICK/caffe/examples/cifar10/cifar10_test_lmdb'
lmdb_env = lmdb.open(db_path)
lmdb_txn = lmdb_env.begin()
lmdb_cursor = lmdb_txn.cursor()
count = 0
correct = 0
for key, value in lmdb_cursor:
print "Count:"
print count
count = count + 1
datum = caffe.proto.caffe_pb2.Datum()
datum.ParseFromString(value)
label = int(datum.label)
image = caffe.io.datum_to_array(datum)
image = image.astype(np.uint8)
out = net.forward_all(data=np.asarray([image]))
predicted_label = out['prob'][0].argmax(axis=0)
print out['prob']
if label == predicted_label:
correct = correct + 1
print("Label is class " + str(label) + ", predicted class is " + str(predicted_label))
print(str(correct) + " out of " + str(count) + " were classified correctly")