How the accuracy is calculated in caffe ?

16 views
Skip to first unread message

jaba marwen

unread,
Jun 9, 2017, 6:20:40 AM6/9/17
to Caffe Users
Hi ,

I trained a simple neural network on the following dataset data set . The dataset consists of 6000 images of three objects piece of plane , a head of motor and and lamborghini.
I know that my dataset is not representative . It have  just few image with different angles and some random noise.
The architecture of neural network is very simple : 1 conv layer , 1 relu , 1 pool and 2 fully connected layer .

I split the data as 4998 for training and 1002 for validation.
After training for 22 epochs I got 88% as accuracy .The problem is when I load the model and retested on the validation data (the validation lmdb directory) using the script I did not get the same accuracy . In fact , I got 54 %.

import os
import glob
import caffe
import lmdb
import numpy as np
from caffe.proto import caffe_pb2

MODEL_FILE
='deploy.prototxt'
PRETRAINED
='snap_shot_model_iter_3500.caffemodel'

caffe
.set_mode_cpu()
#load_model

net
= caffe.Net(MODEL_FILE, PRETRAINED, caffe.TEST)

#load input and configure preprocessing



#mean_file = np.array([104,117,123])

transformer
= caffe.io.Transformer({'data': net.blobs['data'].data.shape})
#transformer.set_mean('data', mean_file)
transformer
.set_transpose('data', (2,0,1))
transformer
.set_channel_swap('data', (2,1,0))
transformer
.set_raw_scale('data', 255.0)


#fixing the batch size

net
.blobs['data'].reshape(1,3,227,227)






lmdb_env
=lmdb.open('/home/jaba/caffe/data/diota_model/val1_lmdb')

lmdb_txn
=lmdb_env.begin()

lmdb_cursor
=lmdb_txn.cursor()

datum
=caffe_pb2.Datum()

correct
=0

for key,value in lmdb_cursor:
   
    datum
.ParseFromString(value)
   
    label
=datum.label
    data
=caffe.io.datum_to_array(datum)
   
    image
=np.transpose(data,(1,2,0))

   
    net
.blobs['data'].data[...]=transformer.preprocess('data',image)

   
out=net.forward()
    out_put
=out['prob'].argmax()
   
   
if out_put==label:
        correct
=correct+1


print correct
       



Would you help me to figure out why I have such results ?
I have attached train.txt and val.txt for preparing lmdb directories, solver.prototxt and train_val.prototxt and deploy.prototxt .







Thanks
deploy.prototxt
solver.prototxt
train_val.prototxt
train.txt
val.txt
Reply all
Reply to author
Forward
0 new messages