caffe SSD 添加新层时出现的问题

来源:互联网 发布:数据库的逻辑设计 编辑:程序博客网 时间:2024/06/06 18:28
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,



0 0
原创粉丝点击