其中mmcv中实现了multi_apply函数实现对多层fpn的处理,这也是为什么在mmdetection的代码中随处可见的*single,其实就是对某一层FPN进行操作,然后最终返回结果中为一个数组。 3.Anchor介绍 3.1 Anchor的生成 Anchor就是预先设定的一个候选框,它的目的就是希望网络可以学习得更好,因为目标检测问题中有不同种类的物体会出...
=multi_apply(self.get_pos_loss_single,cls_scores,objectnesses,reg_loss_list,gt_labels,center_prior_weight_list)pos_avg_factor=reduce_mean(bbox_pred.new_tensor(all_num_gt)).clamp_(min=1)pos_loss=sum(pos_loss_list)/pos_avg_factor# get_pos_loss_single()# p_...
# 注意这里只是根据 cost 大小来分配,只是一个 assign 过程 # 不需要计算梯度,所以用withtorch.no_grad()withtorch.no_grad():reassign_labels,reassign_label_weight,\ reassign_bbox_weights,num_pos=multi_apply(self.paa_reassign,pos_losses_list,labels,labels_weight,bboxes_weight,pos_inds,pos_gt_inde...
def forward(self, feats):# 多尺度特征图,一个一个迭代进行forward_singlereturn multi_apply(self.forward_single, feats)def forward_single(self, x):# 运行各个head独特的head forward方法,得到预测图...return cls_score, bbox_pred... 而对于不同的 head,其 loss 计算部分也比较复杂,可以简单抽象为:l...
losses=self.loss(*loss_inputs,gt_bboxes_ignore=gt_bboxes_ignore)# 返回returnlosses 对于不同的 head,虽然 forward 内容不一样,但是依然可以抽象为:outs = self(x) 代码语言:javascript 复制 defforward(self,feats):# 多尺度特征图,一个一个迭代进行forward_singlereturnmulti_apply(...
importtorchimporttorch.nn as nnimporttorch.nn.functional as Ffrommmcv.runnerimportauto_fp16, force_fp32fromtorch.nn.modules.utilsimport_pairfrommmdet.coreimportbuild_bbox_coder, multi_apply, multiclass_nmsfrommmdet.models.builderimportHEADS, build_lossfrommmdet.models.lossesimportaccuracy ...
importtorchimporttorch.nn as nnimporttorch.nn.functional as Ffrommmcv.runnerimportauto_fp16, force_fp32fromtorch.nn.modules.utilsimport_pairfrommmdet.coreimportbuild_bbox_coder, multi_apply, multiclass_nmsfrommmdet.models.builderimportHEADS, build_lossfrommmdet.models.lossesimportaccuracy ...
然后基于 anchor、gt bbox 以及其他必备信息调用 get_targets 函数计算每个预测分支对应的 target。get_targets 函数内部会调用 multi_apply(_get_targets_single) 函数对每张图片单独计算 target,而 _get_targets_single 函数实现的功能比较多,包括:bbox assigner、bbox sampler 和 bbox encoder 三个关键环节 ...
images_to_levels, multi_apply, multiclass_nms, unmap)from..builderimportHEADS, build_lossfrom.base_dense_headimportBaseDenseHeadfrom.dense_test_mixinsimportBBoxTestMixin @HEADS.register_module()classAnchorHead(BaseDenseHead, BBoxTestMixin):"""Anchor-based head (RPN, RetinaNet, SSD, etc.). ...
I found mmdet use 'multi_apply ' in many implementations, why, only for reducing the loop or it can accelerate training speed?openmmlab-bot assigned yhcao6 Nov 20, 2020 Collaborator yhcao6 commented Nov 21, 2020 No why, it can't accelerate but a way to wrap for-loop. 👍 4 yh...