I have paste my python file which did accuracy testing by my self.
https://dpaste.de/4uC3-------------
import numpy as np
import matplotlib.pyplot as plt
import sys
# Make sure that caffe is on the python path:
caffe_root = '/home/work/caffe/' # this file is expected to be in {caffe_root}/examples
sys.path.insert(0, caffe_root + 'python')
import caffe
from caffe.proto import caffe_pb2
from
caffe.io import blobproto_to_array
MODEL_FILE = '/home/work/caffe/examples/cifar10/cifar10_quick.prototxt'
PRETRAINED = '/home/work/caffe/examples/cifar10/cifar10_quick_iter_5000.caffemodel'
MEAN_FILE= '/home/work/caffe/examples/cifar10/mean.binaryproto'
TEST_FILE = '/home/work/Downloads/cifar-10-batches-py/test_batch'
META_FILE = '/home/work/Downloads/cifar-10-batches-py/batches.meta'
TRAIN_FILE = '/home/work/Downloads/cifar-10-batches-py/data_batch_1'
def unpickle(file_name):
import cPickle
fo = open(file_name, 'rb')
mdict = cPickle.load(fo)
fo.close()
return mdict
def load_mean(mean_file=MEAN_FILE):
blob = caffe_pb2.BlobProto()
data = open(mean_file, "rb").read()
blob.ParseFromString(data)
nparray = blobproto_to_array(blob)
return nparray[0]
def main():
train = unpickle(TRAIN_FILE)
test = unpickle(TEST_FILE)
meta = unpickle(META_FILE)
train_data = train['data']
train_label = train['labels']
test_data = test['data']
test_label = test['labels']
test_data = map(lambda x: x.reshape((32, 32, 3)), test_data)
train_data = map(lambda x: x.reshape((32, 32, 3)), train_data)
net = caffe.Classifier(MODEL_FILE, PRETRAINED,
mean=load_mean(),
channel_swap=(2,1,0),
raw_scale=255,
image_dims=(32, 32))
total, accu = 0, 0
for i, j in zip(train_data, train_label):
total += 1
res = net.predict([i])
if res[0].argmax() == j:
accu += 1
print 'Already run: %s, accuracy: %s'%(total, float(accu)/total)
if __name__ == "__main__":
main()
----------
the outcoming is really no good...
在 2014年10月14日星期二UTC+8下午3时53分24秒,peng yu写道: