1. 程式人生 > >caffe-ssd修改solver.cpp來繪製每一個類的pr曲線

caffe-ssd修改solver.cpp來繪製每一個類的pr曲線

caffe-ssd繪製每個類的pr曲線

1 solver.cpp

進入到caffe-ssd/src/caffe目錄下,開啟solver.cpp。檢視第540行,不同版本可能所在行不同

if (param_.show_per_class_result()) {
        LOG(INFO) << "class" << label << ": " << APs[label];
      }

以上程式碼含義是:讀取solver.prototxt配置檔案中的show_per_class_result引數,若show_per_class_result:true,則在測試的LOG日誌中列印每個類別的Average precision。變數APs是一個map,labels->AP。

這裡我們把程式碼作如下修改,我們引入了一個config控制引數——show_pr:

      if (param_.show_per_class_result()) {
        LOG(INFO) << "class" << label << ": " << APs[label];
        if(param_.show_pr()) 
        {
          for(int i=0;i<p_r.size();i++)
          {
            LOG(INFO) << "p-r value: "
<< p_r[i]; // 列印11個點的precision p_r value(11points) } //write this vector to a txt file //FILE *f = NULL; //f = fopen("/home/bzhang/scripts/0.txt", "w"); //for(int i=0;i<p_r.size();i++) //{ // fprintf(f, "%f\n", p_r[i]); //} //fclose(f);
} }

2 caffe.proto

對應在caffe-ssd/src/caffe/proto/caffe.proto目錄中需要修改,在message SolverParameter中新增

optional bool show_pr = 45 [default = false];

重新make caffe-ssd

3 solver.prototxt

最後在solver.prototxt中將變數值設定為true,即可以在測試階段列印11point value的每一個點的precision,如下:

eval_type: "detection"
ap_version: "11point"
show_per_class_result: true
show_pr_value: true
I0803 12:11:09.125557  5295 solver.cpp:332] Iteration 50000, loss = 1.73973
I0803 12:11:09.125603  5295 solver.cpp:433] Iteration 50000, Testing net (#0)
I0803 12:11:09.155922  5295 net.cpp:693] Ignoring source layer mbox_loss
I0803 12:11:09.688741  5295 blocking_queue.cpp:50] Data layer prefetch queue empty
I0803 12:11:33.173079  5295 solver.cpp:541] class1: 0.675248
I0803 12:11:33.173399  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.173429  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.173437  5295 solver.cpp:546] p-r value: 0.300709
I0803 12:11:33.173451  5295 solver.cpp:546] p-r value: 0.635739
I0803 12:11:33.173460  5295 solver.cpp:546] p-r value: 0.757143
I0803 12:11:33.173466  5295 solver.cpp:546] p-r value: 0.863636
I0803 12:11:33.173473  5295 solver.cpp:546] p-r value: 0.931035
I0803 12:11:33.173480  5295 solver.cpp:546] p-r value: 0.979167
I0803 12:11:33.173488  5295 solver.cpp:546] p-r value: 0.979167
I0803 12:11:33.173496  5295 solver.cpp:546] p-r value: 0.981132
I0803 12:11:33.173502  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.183303  5295 solver.cpp:541] class2: 0.666951
I0803 12:11:33.183322  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.183331  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.183337  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.183344  5295 solver.cpp:546] p-r value: 0.686239
I0803 12:11:33.183351  5295 solver.cpp:546] p-r value: 0.814721
I0803 12:11:33.183359  5295 solver.cpp:546] p-r value: 0.892977
I0803 12:11:33.183367  5295 solver.cpp:546] p-r value: 0.972973
I0803 12:11:33.183373  5295 solver.cpp:546] p-r value: 0.982456
I0803 12:11:33.183380  5295 solver.cpp:546] p-r value: 0.993548
I0803 12:11:33.183388  5295 solver.cpp:546] p-r value: 0.993548
I0803 12:11:33.183396  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.194922  5295 solver.cpp:541] class3: 0.581691
I0803 12:11:33.194939  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.194947  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.194954  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.194960  5295 solver.cpp:546] p-r value: 0.0258479
I0803 12:11:33.194967  5295 solver.cpp:546] p-r value: 0.677273
I0803 12:11:33.194975  5295 solver.cpp:546] p-r value: 0.854167
I0803 12:11:33.194981  5295 solver.cpp:546] p-r value: 0.910714
I0803 12:11:33.194988  5295 solver.cpp:546] p-r value: 0.948454
I0803 12:11:33.194994  5295 solver.cpp:546] p-r value: 0.982143
I0803 12:11:33.195001  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.195008  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.197314  5295 solver.cpp:541] class4: 0.694746
I0803 12:11:33.197352  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.197368  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.197376  5295 solver.cpp:546] p-r value: 0.476548
I0803 12:11:33.197386  5295 solver.cpp:546] p-r value: 0.692547
I0803 12:11:33.197392  5295 solver.cpp:546] p-r value: 0.797521
I0803 12:11:33.197401  5295 solver.cpp:546] p-r value: 0.861702
I0803 12:11:33.197408  5295 solver.cpp:546] p-r value: 0.916084
I0803 12:11:33.197417  5295 solver.cpp:546] p-r value: 0.93578
I0803 12:11:33.197423  5295 solver.cpp:546] p-r value: 0.962025
I0803 12:11:33.197432  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.197439  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.197823  5295 solver.cpp:541] class5: 0.727871
I0803 12:11:33.197835  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.197850  5295 solver.cpp:546] p-r value: 0
I0803 12:11:33.197857  5295 solver.cpp:546] p-r value: 0.547264
I0803 12:11:33.197865  5295 solver.cpp:546] p-r value: 0.813559
I0803 12:11:33.197873  5295 solver.cpp:546] p-r value: 0.88
I0803 12:11:33.197881  5295 solver.cpp:546] p-r value: 0.922078
I0803 12:11:33.197888  5295 solver.cpp:546] p-r value: 0.95082
I0803 12:11:33.197896  5295 solver.cpp:546] p-r value: 0.964286
I0803 12:11:33.197904  5295 solver.cpp:546] p-r value: 0.964286
I0803 12:11:33.197911  5295 solver.cpp:546] p-r value: 0.964286
I0803 12:11:33.197919  5295 solver.cpp:546] p-r value: 1
I0803 12:11:33.197928  5295 solver.cpp:563]     Test net output #0: detection_eval = 0.669301

利用每一個class的每一個precision來繪製pr曲線

繪製pr曲線

這裡推薦自己寫一個parsing log日誌的指令碼,將log日誌的p-r value值讀出,儲存到另一個檔案,供繪製pr曲線程式碼呼叫。

這裡寫圖片描述