美文网首页
2019-01-14

2019-01-14

作者: 带着脑袋生活 | 来源:发表于2019-01-16 21:17 被阅读0次

    此外,计算bbox误差时,不是比较四个角的坐标,而是tx,ty,tw,th,具体计算如下:

    预测的中心点和长宽值

    明明只需要log,    却除以了log(2),转换底,因为c++里面的log是默认以e为底,然而e不好打出来,另外的   fit_ratio是为了让值显得大一些,才进行的。

    train中

    void CHECK_IOU(Anchor<Dtype>& anchor, const std::vector<Box<Dtype>> &GT_Boxes){

    int target_num = GT_Boxes.size();

    Dtype area1 = anchor.width * anchor.height;

    Dtype maxoverlap = 0.f;

    int index = -1;

    for (int i = 0; i < target_num; i++) {

    const Box<Dtype> &gt_box = GT_Boxes[i];

    Dtype x0 = std::max(anchor.x_ctr - anchor.width / 2, gt_box.x0);

    Dtype y0 = std::max(anchor.y_ctr - anchor.height / 2, gt_box.y0);

    Dtype x1 = std::min(anchor.x_ctr + anchor.width / 2, gt_box.x0 + gt_box.width);

    Dtype y1 = std::min(anchor.y_ctr + anchor.height / 2, gt_box.y0 + gt_box.height);

    Dtype area = (x1 - x0 + 1) * (y1 - y0 + 1);

    if (x1 - x0 + 1 < 0 || y1 - y0 + 1 < 0){

    continue;

    }

    Dtype area2 = gt_box.width * gt_box.height;

    Dtype Overlap = area / (area1 + area2 - area);

    if (Overlap > maxoverlap) {

    maxoverlap = Overlap;

    index = i;

    }

    }

    anchor.overlap = maxoverlap;

    if (maxoverlap > Part_overlap) {

    const Box<Dtype> &box = GT_Boxes[index];

    anchor.name = box.name;

    if (maxoverlap > Pos_overlap) {

    anchor.isobject = 2;

    }

    else {

    anchor.isobject = 1;

    }

    anchor.Tar[0] = (box.x0 + box.width / 2 - anchor.x_ctr) / anchor.width;

    anchor.Tar[1] = (box.y0 + box.height / 2 - anchor.y_ctr) / anchor.height;

    anchor.Tar[2] = std::log(box.width / anchor.width) / std::log(2) * fit_ratio;

    anchor.Tar[3] = std::log(box.height / anchor.height) / std::log(2) * fit_ratio;

    }

    else {

    anchor.isobject = 0;

    caffe::caffe_memset(4 * sizeof(Dtype), 0, anchor.Tar);

    }

    if (LabelIndex.count(anchor.name)) {

    anchor.cls = LabelIndex.find(anchor.name)->second;

    }

    }

    test中

    微调box

    template < typename Dtype >

    inline void ReassignBox(Box &box, const Anchor<Dtype> &anchor,

    Dtype x_ctr_off, Dtype y_ctr_off, Dtype w_off, Dtype h_off){

    box.width = std::pow(2, w_off / fit_ratio) * anchor.width;

    box.height = std::pow(2, h_off / fit_ratio) * anchor.height;

    box.x0 = x_ctr_off * anchor.width + anchor.x_ctr - box.width / 2;

    box.y0 = y_ctr_off * anchor.height + anchor.y_ctr - box.height / 2;

    }

    相关文章

      网友评论

          本文标题:2019-01-14

          本文链接:https://www.haomeiwen.com/subject/zqgddqtx.html