为什么Caffe准确度层报告的准确度与pycaffe报告的准确度不同?

时间:2018-03-29 14:07:38

标签: caffe pycaffe

我有训练阶段和测试阶段的准确度层 我还尝试训练Caffe形式PyCaffe,以便我可以更好地绘制曲线 但是我注意到,使用

返回的准确性
solver.test_nets[0].blobs['accuracy'].data

与我自己计算的不同:

def run_test(solver, test_iter):
    '''
    Tests the network on all test set and calculates the test accuracy
    '''
    correct = 0
    batch_size_test =  solver.test_nets[0].blobs['data'].data.shape[0]

    for test_it in range(test_iter):
        #testing the network on all test set and calculate the test accuracy
        solver.test_nets[0].forward()
        correct += sum(solver.test_nets[0].blobs['ip1'].data.argmax(1) == solver.test_nets[0].blobs['label'].data)

    acc = correct / (test_iter * batch_size_test)
    return acc

run_test返回的准确度与Caffe在控制台屏幕上报告的准确度相同 问题是什么?
我也有这个问题与训练阶段的准确性和损失,意味着再次

    train_loss[it] = solver.net.blobs['loss'].data
    training_acc = str(solver.net.blobs['accuracy_training'].data)

与Caffe在控制台屏幕中报告的值不同。

1 个答案:

答案 0 :(得分:1)

我在这里犯了一个错误! 一切都还可以,除了我应该只用test_iter次来划分积累的精度:

def run_test(solver, test_iter):
    '''
    Tests the network on all test set and calculates the test accuracy
    '''
    correct = 0
    batch_size_test =  solver.test_nets[0].blobs['data'].data.shape[0]

    for test_it in range(test_iter):
        #testing the network on all test set and calculate the test accuracy
        solver.test_nets[0].forward()
        correct += solver.test_nets[0].blobs['accuracy'].data

    acc = correct / test_iter
    return acc 

摘录:

solver.test_nets[0].blobs['accuracy'].data

将产生单个批次的准确性,显然为了获得整个测试集的准确性,它们需要累计test_iter次,然后除以test_iter