【caffe】修改SSD的solver输出recall和precision

我们可以从SSD的caffe源码中得到test的mAP,mAP是不同阈值下的precision均值,但如果我们想看某个阈值下的recallprecision时,就需要对solver.cpp源码做一定修改。
关于mAP, recall和precision的解释这里不赘述,可以参考以下博客:
中文介绍
英文介绍

修改caffe.proto

首先在src/caffe/proto/caffe.proto中的SolverParameter这个message下加上一个参数rec_prec_thr,该参数是判断样本是否为true positive (tp) 的score阈值,我们给他一个默认值0.6,代码如下(注意序列号在自己的SolverParameter最后的序列号上加1)

optional float rec_prec_thr = 45 [default = 0.6];

修改solver.cpp

接下来在src/caffe/solver.cpp的void Solver<Dtype>::TestDetection(const int test_net_id)函数中加入计算recall和precision的代码:

template <typename Dtype>
void Solver<Dtype>::TestDetection(const int test_net_id) {
  CHECK(Caffe::root_solver());
  LOG(INFO) << "Iteration " << iter_
            << ", Testing net (#" << test_net_id << ")";
  CHECK_NOTNULL(test_nets_[test_net_id].get())->
      ShareTrainedLayersWith(net_.get());
  map<int, map<int, vector<pair<float, int> > > > all_true_pos;
  map<int, map<int, vector<pair<float, int> > > > all_false_pos;
  map<int, map<int, int> > all_num_pos;
  const shared_ptr<Net<Dtype> >& test_net = test_nets_[test_net_id];
  Dtype loss = 0;
  for (int i = 0; i < param_.test_iter(test_net_id); ++i) {
    SolverAction::Enum request = GetRequestedAction();
    
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值