Skip to content
Pulkit edited this page Feb 23, 2016 · 4 revisions

Utilities for easily evaluating trained caffe models.

##Using LMDB

An example that tests AlexNet.

import my_pycaffe_utils as mpu
#Initialize the testing object
cTest = mpu.CaffeTest.from_model(net_prototxt_file, net_caffemodel_file,
        gpu_id=0, lmdbTest='/path/to/test_lmdb')
'''
Setup the network
input image size: imH, imW
crop image size:  cropH, cropW
opNames: the layer whose output is the prediction or if the goal is just to extract features
         then layernames whose features should be extracted. 
'''
cTest.setup_network(opNames=['fc8'], imH=256, imW=256, cropH=227,
                   cropW=227, batchSz=100,
                   meanFile='path_to_mean_file')
#Run the net on the entire LMDB
cTest.run_test()
#Instead, if you just want to get the features use
feats, label, valid = cTest.get_data()
#Compute the performance
'''
accType: accClassMean - calculate mean accuracy across classes
         acc - overall mean accuracy
'''
acc = cTest.compute_performance(accType='accClassMean')
Clone this wiki locally