1. 程式人生 > >caffe SSD 新增新層時出現的問題

caffe SSD 新增新層時出現的問題

caffe程式碼,在迭代10000次的時候需要進行test,但是test的時候遇見問題。
I0512 14:40:29.685868 15163 upgrade_proto.cpp:77] Attempting to upgrade batch norm layers using deprecated params: snapshot_iter_10000.caffemodel
I0512 14:40:29.685925 15163 upgrade_proto.cpp:80] Successfully upgraded batch norm layers using deprecated params.
I0512 14:40:29.710816 15163 sgd_solver.cpp:356] SGDSolver: restoring history
I0512 14:40:29.788755 15163 caffe.cpp:251] Starting Optimization
I0512 14:40:29.788800 15163 solver.cpp:294] Solving VGG_VOC0712_SSD_300x300_test_train
I0512 14:40:29.788805 15163 solver.cpp:295] Learning Rate Policy: multistep
I0512 14:40:29.799832 15163 solver.cpp:433] Iteration 10000, Testing net (#0)
I0512 14:40:29.817718 15163 net.cpp:693] Ignoring source layer mbox_loss
F0512 14:40:32.193830 15163 solver.cpp:464] Check failed: result[j]->width() == 5 (150 vs. 5)
*** Check failure stack trace: ***
    @     0x7f82cfdf75cd  google::LogMessage::Fail()
    @     0x7f82cfdf9433  google::LogMessage::SendToLog()
    @     0x7f82cfdf715b  google::LogMessage::Flush()
    @     0x7f82cfdf9e1e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7f82d04aef2c  caffe::Solver<>::TestDetection()
    @     0x7f82d04afe39  caffe::Solver<>::TestAll()
    @     0x7f82d04aff3c  caffe::Solver<>::Step()
    @     0x7f82d04b0abe  caffe::Solver<>::Solve()
    @           0x40bcf4  train()
    @           0x4077c8  main
    @     0x7f82ce58e830  __libc_start_main
    @           0x408099  _start
    @              (nil)  (unknown)
Aborted (core dumped)

注:遇見問題,如果丟擲錯誤,首先要去讀原始碼。例如這個,要去solver.cpp中,看丟擲的問題在什麼地方。

看不懂程式碼也是悲傷!


SSD的solver原始碼 為什麼在test的時候,對每一次獲得的blob 的width要和5進行對比呢?
*******************solver原始碼分割線**********************
    Dtype iter_loss;
    const vector<Blob<Dtype>*>& result = test_net->Forward(&iter_loss);
    if (param_.test_compute_loss()) {
      loss += iter_loss;
    }
    for (int j = 0; j < result.size(); ++j) {
      CHECK_EQ(result[j]->width(), 5);
      const Dtype* result_vec = result[j]->cpu_data();
      int num_det = result[j]->height();
      for (int k = 0; k < num_det; ++k) {
        int item_id = static_cast<int>(result_vec[k * 5]);
        int label = static_cast<int>(result_vec[k * 5 + 1]);
        if (item_id == -1) {
          // Special row of storing number of positives for a label.
          if (all_num_pos[j].find(label) == all_num_pos[j].end()) {
            all_num_pos[j][label] = static_cast<int>(result_vec[k * 5 + 2]);
          } else {
            all_num_pos[j][label] += static_cast<int>(result_vec[k * 5 + 2]);
          }
        } else {
          // Normal row storing detection status.
          float score = result_vec[k * 5 + 2];
          int tp = static_cast<int>(result_vec[k * 5 + 3]);
          int fp = static_cast<int>(result_vec[k * 5 + 4]);
          if (tp == 0 && fp == 0) {
            // Ignore such case. It happens when a detection bbox is matched to
            // a difficult gt bbox and we don't evaluate on difficult gt bbox.
            continue;
          }
          all_true_pos[j][label].push_back(std::make_pair(score, tp));
          all_false_pos[j][label].push_back(std::make_pair(score, fp));
        }
      }
    }
  }


***********************************2017/5/13*********************************
去git的主頁上找到了一個人遇見了同樣的問題,新增新的層會遇見同樣的問題
原問題:

Thanks to Wei for the great work, and sharing it with everybody.

I need to get TEST loss during training, so that I can get some idea about how well the network is doing in generalization. In the python script I tried to add MultiBoxLoss layer to the test net the same way train net did, however it give me error at test time:
solver.cpp:464 check failed: result[j]->width() ==5 (1 vs 5)

I am not familiar with the internals of Caffe, could you give me a pointer on proper way of enabling test loss in the Python script?
Your help is greatly appreciated.

作者回答:
I think you have to add a silence layer after the loss layer.
在python的介面的程式碼

in the python script,when you create the test net, after CreateMultiBoxHead, add these lines

name = "test_loss"
mbox_layers.append(net.label)
net[name] = L.MultiBoxLoss(*mbox_layers, multibox_loss_param=multibox_loss_param,
        loss_param=loss_param, include=dict(phase=caffe_pb2.Phase.Value('TEST')),
        propagate_down=[True, True, False, False])
 name="silence"
 net[name] = L.Silence(net['test_loss'],ntop=0)

also, add this to the solver_param:
'test_compute_loss':True,