def loss(self, cls_scores, bbox_preds, gt_bboxes, gt_labels, img_metas, cfg, gt_bboxes_ignore=None): featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores] assert len(featmap_sizes) == len(self.anchor_generators) device = cls_scores[0].device anchor_list, valid_flag_list = self.get_anchors(featmap_sizes, img_metas, device=device) label_channels = self.cls_out_channels if self.use_sigmoid_cls else 1 cls_reg_targets = anchor_target_rotated( anchor_list, valid_flag_list, gt_bboxes, img_metas, self.target_means, self.target_stds, cfg, bbox_preds=bbox_preds, gt_bboxes_ignore_list=gt_bboxes_ignore, gt_labels_list=gt_labels, label_channels=label_channels, sampling=self.sampling) if cls_reg_targets is None: return None (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_pos, num_total_neg) = cls_reg_targets num_total_samples = (num_total_pos + num_total_neg if self.sampling else num_total_pos) anchor_list, valid_flag_list = self.get_anchors(featmap_sizes, img_metas, device=device) nB = len(anchor_list) nL = len(anchor_list[0]) anchors = [[0] * nB for _ in range(nL)] for nb in range(nB): for nl in range(nL): anchors[nl][nb] = anchor_list[nb][nl] anchor_list = [torch.stack(_anchors) for _anchors in anchors] losses_cls, losses_bbox = multi_apply( self.loss_single, cls_scores, bbox_preds, labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, anchor_list, num_total_samples=num_total_samples, cfg=cfg) return dict(loss_cls=losses_cls, loss_bbox=losses_bbox)
def loss(self, fam_cls_scores, fam_bbox_preds, refine_anchors, odm_cls_scores, odm_bbox_preds, gt_bboxes, gt_labels, img_metas, cfg, gt_bboxes_ignore=None): featmap_sizes = [featmap.size()[-2:] for featmap in odm_cls_scores] assert len(featmap_sizes) == len(self.anchor_generators) device = odm_cls_scores[0].device anchors_list, valid_flag_list = self.get_init_anchors(featmap_sizes, img_metas, device=device) # Feature Alignment Module tagets label_channels = self.cls_out_channels if self.use_sigmoid_cls else 1 cls_reg_targets = anchor_target_rotated( anchors_list, valid_flag_list, gt_bboxes, img_metas, self.target_means, self.target_stds, cfg.fam_cfg, bbox_preds=fam_bbox_preds, gt_bboxes_ignore_list=gt_bboxes_ignore, gt_labels_list=gt_labels, label_channels=label_channels, sampling=self.sampling) if cls_reg_targets is None: return None (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_pos, num_total_neg) = cls_reg_targets num_total_samples = (num_total_pos + num_total_neg if self.sampling else num_total_pos) losses_fam_cls, losses_fam_bbox = multi_apply( self.loss_fam_single, fam_cls_scores, fam_bbox_preds, labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_samples=num_total_samples, cfg=cfg.fam_cfg) # Object Detection Module targets refine_anchors_list, valid_flag_list = self.get_refine_anchors( featmap_sizes, refine_anchors, img_metas, device=device) label_channels = self.cls_out_channels if self.use_sigmoid_cls else 1 cls_reg_targets = anchor_target_rotated( refine_anchors_list, valid_flag_list, gt_bboxes, img_metas, self.target_means, self.target_stds, cfg.odm_cfg, bbox_preds=odm_bbox_preds, gt_bboxes_ignore_list=gt_bboxes_ignore, gt_labels_list=gt_labels, label_channels=label_channels, sampling=self.sampling) if cls_reg_targets is None: return None (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_pos, num_total_neg) = cls_reg_targets num_total_samples = (num_total_pos + num_total_neg if self.sampling else num_total_pos) losses_odm_cls, losses_odm_bbox = multi_apply( self.loss_odm_single, odm_cls_scores, odm_bbox_preds, labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, refine_anchors, num_total_samples=num_total_samples, cfg=cfg.odm_cfg) return dict(loss_fam_cls=losses_fam_cls, loss_fam_bbox=losses_fam_bbox, loss_odm_cls=losses_odm_cls, loss_odm_bbox=losses_odm_bbox)
def loss(self, ref_bbox_preds, refine_anchors, cls_scores, bbox_preds, gt_bboxes, gt_labels, img_metas, cfg, gt_bboxes_ignore=None): featmap_sizes = [featmap.size()[-2:] for featmap in cls_scores] assert len(featmap_sizes) == len(self.anchor_generators) device = cls_scores[0].device anchors_list, valid_flag_list = self.get_init_anchors( featmap_sizes, img_metas, device=device) # Anchor Refinement Module loss label_channels = self.cls_out_channels if self.use_sigmoid_cls else 1 cls_reg_targets = anchor_target_rotated( anchors_list, valid_flag_list, gt_bboxes, img_metas, self.target_means, self.target_stds, cfg.ref_cfg, bbox_preds=ref_bbox_preds, gt_bboxes_ignore_list=gt_bboxes_ignore, gt_labels_list=gt_labels, label_channels=label_channels, sampling=self.sampling) if cls_reg_targets is None: return None (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_pos, num_total_neg) = cls_reg_targets num_total_samples = ( num_total_pos + num_total_neg if self.sampling else num_total_pos) losses_ref_bbox = [] for level in range(len(ref_bbox_preds)): losses_ref_bbox.append(self.loss_ref_single(ref_bbox_preds[level], bbox_targets_list[level], bbox_weights_list[level], num_total_samples=num_total_samples, cfg=cfg.ref_cfg)) # Detection Module loss refine_anchors_list, valid_flag_list = self.get_refine_anchors( featmap_sizes, refine_anchors, img_metas, device=device) label_channels = self.cls_out_channels if self.use_sigmoid_cls else 1 cls_reg_targets = anchor_target_rotated( refine_anchors_list, valid_flag_list, gt_bboxes, img_metas, self.target_means, self.target_stds, cfg.odm_cfg, bbox_preds=bbox_preds, gt_bboxes_ignore_list=gt_bboxes_ignore, gt_labels_list=gt_labels, label_channels=label_channels, sampling=self.sampling) if cls_reg_targets is None: return None (labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_pos, num_total_neg) = cls_reg_targets num_total_samples = ( num_total_pos + num_total_neg if self.sampling else num_total_pos) losses_odm_cls, losses_odm_bbox = multi_apply( self.loss_odm_single, cls_scores, bbox_preds, labels_list, label_weights_list, bbox_targets_list, bbox_weights_list, num_total_samples=num_total_samples, cfg=cfg.odm_cfg) return dict(loss_ref_bbox=losses_ref_bbox, loss_odm_cls=losses_odm_cls, loss_odm_bbox=losses_odm_bbox)