Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong caffemodel? #13

Open
suikammd opened this issue Jan 14, 2019 · 0 comments
Open

Wrong caffemodel? #13

suikammd opened this issue Jan 14, 2019 · 0 comments

Comments

@suikammd
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant