lim0606 / caffe-googlenet-bn

re-implementation of googlenet batch normalization
131 stars 77 forks source link

Wrong caffemodel? #13

Open suikammd opened 5 years ago

suikammd commented 5 years ago

I test the caffemodel using the following methods, but it turns out a low accuracy? Maybe the caffemodel not the right one?

import caffe
import numpy as np
net_file = './caffe-googlenet-bn/deploy.prototxt'
model = './caffe-googlenet-bn/snapshots/googlenet_bn_stepsize_6400_iter_1200000.caffemodel'

caffe.set_mode_gpu()
caffe.set_device(0)
net = caffe.Net(net_file, model, caffe.TEST)
image_mean = np.load('./mean.npy')
image_path = '/data/ImageNet2012/ILSVRC2012/ILSVRC2012_img_val/'
image_txt = './label.txt'

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

count = 0
print "start!"
for line in f.readlines():
    line = line.strip().split(" ")
    img = image_path + line[0]
    image = caffe.io.load_image(img)
    transformed_image = transformer.preprocess('data', image)
    net.blobs['data'].data[...] = transformed_image
    output = net.forward()
    output_prob = output['prob'][0]
    if int(line[1]) in output_prob.argsort()[-5:]:
            count += 1
    print "accuracy", count * 1.0 / i, count

print "top5: %lf", count * 1.0 / 50000

Thanks for your response!