【问题标题】:Why is the accuracy reported by Caffe accuracy layer differs from the one reported in pycaffe?为什么 Caffe 准确率层报告的准确率与 pycaffe 报告的准确率不同?
【发布时间】:2018-03-29 14:07:37
【问题描述】:

我在训练阶段和测试阶段都有一个准确度层。
我还尝试从PyCaffe 训练Caffe,以便更好地绘制曲线。
但是我注意到,使用

返回的准确性
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 在控制台屏幕中报告的值不同。

【问题讨论】:

    标签: caffe pycaffe


    【解决方案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 
    

    sn-p:

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

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

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 1970-01-01
      • 2023-02-16
      • 2023-03-04
      • 2014-02-28
      • 2020-07-27
      • 1970-01-01
      • 2016-02-19
      相关资源
      最近更新 更多