0

I have trained CIFAR QUICK using caffe, but when I test the cifar10_quick_iter_5000.caffemodel.h5 using a python wrapper I get an accuracy around 52-54% whereas it should be 75%. I do not understand why I am geting such a low accuracy, because when I test Lenet MNIST I get the expected accuracy as per the MNIST example in caffe website. To verify if my method is right or wrong I have tried the cifar trained model file from Clasificador_Cifar-10 and I get and accuracy of 68%.

Please let me know if I am missing something when I test the model.

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")
  • why do you convert the input image to uint8? what about other input transformations? – Shai Feb 23 '16 at 06:03
  • Well, this whole set up was suggested in the caffe mail group [thread](https://groups.google.com/forum/#!searchin/caffe-users/mnist/caffe-users/KHCU6Ti5gSQ/kb-FYv8ELOsJ) I am not sure why unit8, but just to check I comment that line but results were the same. – Fradaric Joseph Feb 23 '16 at 10:34

1 Answers1

0

See my answer here. You are not subtracting the mean which results in low accuracy. The link to the code, posted above, takes care of that. Apart from this there's nothing wrong with your approach.

Community
  • 1
  • 1
Harsh Wardhan
  • 2,110
  • 10
  • 36
  • 51