咖啡精度大于100% [英] Caffe accuracy bigger than 100%

查看:82
本文介绍了咖啡精度大于100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建造一个,但是,当我使用

I'm building one but, and when I use the custom train function provided on lenet example with a batch size bigger than 110 my accuracy gets bigger than 1 (100%).

如果我使用批处理大小为32,则可以获得30%的准确度.批次大小等于64我的净精度为64.而批次大小等于128,则精度为1.2.

If I use batch size 32, I get 30 percent of accuracy. Batch size equal 64 my net accuracy is 64. And batch size equal to 128, the accuracy is 1.2.

我的图片是32x32. 训练数据集:56张中性脸图像.惊喜面孔的60张图像.测试数据集:15张中性脸图像. 15张惊喜面孔的图像.

My images are 32x32. Train dataset: 56 images of Neutral faces. 60 images of Surprise faces. Test dataset: 15 images of Neutral faces. 15 images of Surprise faces.

这是我的代码:

def train(solver):

niter = 200
test_interval = 25 

train_loss = zeros(niter)
test_acc = zeros(int(np.ceil(niter / test_interval)))
output = zeros((niter, 32, 2))

for it in range(niter):
    solver.step(1)
    train_loss[it] = solver.net.blobs['loss'].data
    solver.test_nets[0].forward(start='conv1')
    output[it] = solver.test_nets[0].blobs['ip2'].data[:32]
    if it % test_interval == 0:
        print 'Iteration', it, 'testing...'

        correct = 0

        for test_it in range(100):
            solver.test_nets[0].forward()
            correct += sum(solver.test_nets[0].blobs['ip2'].data.argmax(1) == solver.test_nets[0].blobs['label'].data)

        test_acc[it // test_interval] = correct / 1e4

那么,我的代码有什么问题?

So, what is wrong with my code?

推荐答案

在测试代码中,您运行100次迭代(for test_it in range(100)),在每次迭代中,您将correct计算为批处理是正确的.然后,将该数字除以1e4.

In your testing code you run 100 iterations (for test_it in range(100)), on each iteration you compute correct as number of examples in a batch that are correct. You then divide that number by 1e4.

让我们假设您的模型非常好,预测率几乎为100%.然后,每100次迭代的批处理大小为32,您将在correct上加32,得到3200.然后将其除以1e4,最后得到0.32,这几乎与您看到的一致(您的数目稍少,因为有时您的模型会错误地预测目标).

Let's assume your model is very good and has almost 100% prediction rate. Then with batch size of 32 on each of 100 iterations you will add 32 to correct, yielding 3200. You then divide it by 1e4, ending up with 0.32, which is almost consistent with what you see (your number is slightly less because sometimes your model does mispredict the target).

要修复此问题,可以替换

To fix it, you can replace

test_acc[it // test_interval] = correct / 1e4

使用

test_acc[it // test_interval] = correct / (100.0 * batch_size)

这篇关于咖啡精度大于100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆