ssd中的match规则

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

def match

代码如下():
理解须知:
《1》torch.max(a,dim=0,keepdim=True) dim=1,表示 the dimension to reduce(这个维度上减少消去)
《2》index_fill_(dim,index,val)按照指定的维度轴dim 根据index去对应位置,将原tensor用参数val值填充,这里强调一下,index必须是1D tensor,index去指定轴上索引数据时候会广播
特别感谢下这位同志的笔记:豆豆小朋友的笔记:添加链接描述
《3》下图表示的为真实框(ground_truth)和先验框(priors)相互匹配得到的交并比值(overlap)和地址(idx),其中数据可能会影响结果的确切性
问题版:在这里插入图片描述
正确版:
在这里插入图片描述

def match(threshold, truths, priors, variances, labels, loc_t, conf_t, idx):
    #----------------------------------------------#
    #   计算所有的先验框和真实框的重合程度
    #----------------------------------------------#
    overlaps = jaccard(
        truths,
        point_form(priors)
    )
    #----------------------------------------------#
    #   所有真实框和先验框的最好重合程度        # 拿先验框来去匹配真实框,与每个真实框的最好匹配结果
    #   best_prior_overlap [truth_box,1]
    #   best_prior_idx [truth_box,0]
    #----------------------------------------------#
    # https: // blog.popkx.com/detail-analysis-of-retinaface-multibox-loss-priorbox-and-object-bbox-matches-analysis/
    # torch.max(a,dim=0,keepdim=True)     dim=1,表示 the dimension to reduce(这个维度上减少消去)
    best_prior_overlap, best_prior_idx = overlaps.max(1, keepdim=True)
    best_prior_idx.squeeze_(1)      # 变为tensor
    best_prior_overlap.squeeze_(1)
    #----------------------------------------------#
    #   所有先验框和真实框的最好重合程度        # 拿真实框来去匹配先验框,与每个先验框的最好匹配结果
    #   best_truth_overlap [1,prior]
    #   best_truth_idx [1,prior]
    #----------------------------------------------#
    # torch.max(a,dim=0,keepdim=True)     dim=0,表示 the dimension to reduce(这个维度上减少消去)
    best_truth_overlap, best_truth_idx = overlaps.max(0, keepdim=True)
    best_truth_idx.squeeze_(0)
    best_truth_overlap.squeeze_(0)

    #----------------------------------------------#
    #   用于保证每个真实框都至少有对应的一个先验框
    #----------------------------------------------#
    for j in range(best_prior_idx.size(0)):
        best_truth_idx[best_prior_idx[j]] = j
    best_truth_overlap.index_fill_(0, best_prior_idx, 2)
    
    #----------------------------------------------#
    #   获取每一个先验框对应的真实框[num_priors,4]
    #----------------------------------------------#
    matches = truths[best_truth_idx]
    # Shape: [num_priors]
    conf = labels[best_truth_idx] + 1

    #----------------------------------------------#
    #   如果重合程度小于threhold则认为是背景
    #----------------------------------------------#
    conf[best_truth_overlap < threshold] = 0
    
    #----------------------------------------------#
    #   利用真实框和先验框进行编码
    #   编码后的结果就是网络应该有的预测结果
    #----------------------------------------------#
    loc = encode(matches, priors, variances)

    # [num_priors,4]
    loc_t[idx] = loc    
    # [num_priors]
    conf_t[idx] = conf  
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值