def get_refined_proposal(backbone, neck, rpn_head, roi_extractor, bbox_head, bbox_head_2nd, bbox_head_3rd, stage): rec_id, im_id, im_info, proposal, proposal_score = CascadeRcnn.get_rpn_test_symbol( backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) # stage1 roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) _, bbox_xyxy = bbox_head.get_prediction(roi_feat, im_info, proposal) # stage2 proposal_2nd = bbox_xyxy roi_feat_2nd = roi_extractor.get_roi_feature(rcnn_feat, proposal_2nd) _, bbox_xyxy_2nd = bbox_head_2nd.get_prediction( roi_feat_2nd, im_info, proposal_2nd) # stage3 proposal_3rd = bbox_xyxy_2nd roi_feat_3rd = roi_extractor.get_roi_feature(rcnn_feat, proposal_3rd) cls_score_3rd, bbox_xyxy_3rd = bbox_head_3rd.get_prediction( roi_feat_3rd, im_info, proposal_3rd) # AR does not need score, just pass a dummy one if stage == 2: return X.group( [rec_id, im_id, im_info, proposal_2nd, cls_score_3rd]) elif stage == 3: return X.group( [rec_id, im_id, im_info, proposal_3rd, cls_score_3rd])
def get_train_symbol(backbone, neck, rpn_head, bbox_roi_extractor, mask_roi_extractor, bbox_head, mask_head, maskiou_head): gt_bbox = X.var("gt_bbox") gt_poly = X.var("gt_poly") im_info = X.var("im_info") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_head.get_anchor() rpn_loss = rpn_head.get_loss(rpn_feat, gt_bbox, im_info) proposal, bbox_cls, bbox_target, bbox_weight, mask_proposal, mask_target, mask_ind, mask_ratio = \ rpn_head.get_sampled_proposal(rpn_feat, gt_bbox, gt_poly, im_info) roi_feat = bbox_roi_extractor.get_roi_feature(rcnn_feat, proposal) mask_roi_feat = mask_roi_extractor.get_roi_feature( rcnn_feat, mask_proposal) bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) mask_loss, mask_pred_logits = mask_head.get_loss( mask_roi_feat, mask_target, mask_ind) iou_loss = maskiou_head.get_loss(mask_roi_feat, mask_pred_logits, mask_target, mask_ind, mask_ratio) return X.group(rpn_loss + bbox_loss + mask_loss + iou_loss)
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, mask_roi_extractor, bbox_head, mask_head, bbox_post_processor, num_branch): rec_id, im_id, im_info, proposal, proposal_score = \ TridentFasterRcnn.get_rpn_test_symbol(backbone, neck, rpn_head, num_branch) im_info_branches = TridentResNetV2Builder.stack_branch_symbols( [im_info] * num_branch) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info_branches, proposal) post_cls_score, post_bbox_xyxy, post_cls = bbox_post_processor.get_post_processing( cls_score, bbox_xyxy) mask_roi_feat = mask_roi_extractor.get_roi_feature( rcnn_feat, post_bbox_xyxy) mask = mask_head.get_prediction(mask_roi_feat) # fold batch size into roi size for trident only post_cls_score = X.reshape(post_cls_score, (-3, -2), name="post_cls_score_fold") post_bbox_xyxy = X.reshape(post_bbox_xyxy, (-3, -2), name="post_bbox_xyxy_fold") post_cls = X.reshape(post_cls, (-3, -2), name="post_cls_fold") return X.group([ rec_id, im_id, im_info, post_cls_score, post_bbox_xyxy, post_cls, mask ])
def get_test_symbol(backbone, neck, rpn_head, bbox_roi_extractor, mask_roi_extractor, bbox_head, mask_head, bbox_post_processor, maskiou_head): rec_id, im_id, im_info, proposal, proposal_score = \ MaskScoringRcnn.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = bbox_roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info, proposal) post_cls_score, post_bbox_xyxy, post_cls = bbox_post_processor.get_post_processing( cls_score, bbox_xyxy) mask_roi_feat = mask_roi_extractor.get_roi_feature( rcnn_feat, post_bbox_xyxy) mask = mask_head.get_prediction(mask_roi_feat) iou_pred = maskiou_head.get_maskiou_prediction(mask, mask_roi_feat, post_cls) return X.group([ rec_id, im_id, im_info, post_cls_score, post_bbox_xyxy, post_cls, mask, iou_pred ])
def get_train_symbol(backbone, neck, rpn_head, roi_extractor, mask_roi_extractor, bbox_head, mask_head): gt_bbox = X.var("gt_bbox") gt_poly = X.var("gt_poly") im_info = X.var("im_info") rpn_cls_label = X.var("rpn_cls_label") rpn_reg_target = X.var("rpn_reg_target") rpn_reg_weight = X.var("rpn_reg_weight") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_loss = rpn_head.get_loss(rpn_feat, rpn_cls_label, rpn_reg_target, rpn_reg_weight) proposal, bbox_cls, bbox_target, bbox_weight, mask_proposal, mask_target = \ rpn_head.get_sampled_proposal(rpn_feat, gt_bbox, gt_poly, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) mask_roi_feat = mask_roi_extractor.get_roi_feature( rcnn_feat, mask_proposal) bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) mask_loss = mask_head.get_loss(mask_roi_feat, mask_target) return X.group(rpn_loss + bbox_loss + mask_loss)
def get_train_symbol(backbone, neck, rpn_head, roi_extractor, bbox_head, \ bbox_head_2nd, bbox_head_3rd): gt_bbox = X.var("gt_bbox") im_info = X.var("im_info") rpn_cls_label = X.var("rpn_cls_label") rpn_reg_target = X.var("rpn_reg_target") rpn_reg_weight = X.var("rpn_reg_weight") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_loss = rpn_head.get_loss(rpn_feat, rpn_cls_label, rpn_reg_target, rpn_reg_weight) # stage1 proposal, bbox_cls, bbox_target, bbox_weight = \ rpn_head.get_sampled_proposal( rpn_feat, gt_bbox, im_info ) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal, "1st") bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) bbox_pred = bbox_head._bbox_delta # stage2 # though call get_sampled_proposal, bbox_head does not sample rois proposal_2nd, bbox_cls_2nd, bbox_target_2nd, bbox_weight_2nd = \ bbox_head.get_sampled_proposal( proposal, bbox_pred, gt_bbox, im_info ) roi_feat_2nd = roi_extractor.get_roi_feature(rcnn_feat, proposal_2nd, "2nd") bbox_loss_2nd = bbox_head_2nd.get_loss(roi_feat_2nd, bbox_cls_2nd, bbox_target_2nd, bbox_weight_2nd) bbox_pred_2nd = bbox_head_2nd._bbox_delta # stage3 # though call get_sampled_proposal, bbox_head does not sample rois proposal_3rd, bbox_cls_3rd, bbox_target_3rd, bbox_weight_3rd = \ bbox_head_2nd.get_sampled_proposal( proposal_2nd, bbox_pred_2nd, gt_bbox, im_info ) roi_feat_3rd = roi_extractor.get_roi_feature(rcnn_feat, proposal_3rd, "3rd") bbox_loss_3rd = bbox_head_3rd.get_loss(roi_feat_3rd, bbox_cls_3rd, bbox_target_3rd, bbox_weight_3rd) return X.group(rpn_loss + bbox_loss + bbox_loss_2nd + bbox_loss_3rd)
def get_train_symbol(cls, backbone, neck, rpn_head): rpn_feat = backbone.get_rpn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rpn_loss = rpn_head.get_loss(rpn_feat, None, None) return X.group(rpn_loss)
def get_train_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head, num_branch, scaleaware): gt_bbox = X.var("gt_bbox") im_info = X.var("im_info") if scaleaware: valid_ranges = X.var("valid_ranges") rpn_cls_label = X.var("rpn_cls_label") rpn_reg_target = X.var("rpn_reg_target") rpn_reg_weight = X.var("rpn_reg_weight") im_info = TridentResNetV2Builder.stack_branch_symbols([im_info] * num_branch) gt_bbox = TridentResNetV2Builder.stack_branch_symbols([gt_bbox] * num_branch) if scaleaware: valid_ranges = X.reshape(valid_ranges, (-3, -2)) rpn_cls_label = X.reshape(rpn_cls_label, (-3, -2)) rpn_reg_target = X.reshape(rpn_reg_target, (-3, -2)) rpn_reg_weight = X.reshape(rpn_reg_weight, (-3, -2)) rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_loss = rpn_head.get_loss(rpn_feat, rpn_cls_label, rpn_reg_target, rpn_reg_weight) if scaleaware: proposal, bbox_cls, bbox_target, bbox_weight = rpn_head.get_sampled_proposal_with_filter(rpn_feat, gt_bbox, im_info, valid_ranges) else: proposal, bbox_cls, bbox_target, bbox_weight = rpn_head.get_sampled_proposal(rpn_feat, gt_bbox, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) return X.group(rpn_loss + bbox_loss)
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, mask_roi_extractor, bbox_head, mask_head, bbox_post_processor): im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) proposal = rpn_head.get_all_proposal(rpn_feat, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info, proposal) post_cls_score, post_bbox_xyxy, post_cls = bbox_post_processor.get_post_processing( cls_score, bbox_xyxy) mask_roi_feat = mask_roi_extractor.get_roi_feature( rcnn_feat, post_bbox_xyxy) mask = mask_head.get_prediction(mask_roi_feat) return X.group([ rec_id, im_id, im_info, post_cls_score, post_bbox_xyxy, post_cls, mask ])
def get_test_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head): rec_id, im_id, im_info, proposal, proposal_score = \ FasterRcnn.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature_test(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info, proposal) if is_deploy: out = X.group([im_info, cls_score, bbox_xyxy]) else: out = X.group([rec_id, im_id, im_info, cls_score, bbox_xyxy]) return out
def get_train_symbol(backbone, neck, head): label = X.var("gt_bbox") feat = backbone.get_rpn_feature() feat = neck.get_rpn_feature(feat) loss = head.get_loss(feat, label) return X.group(loss)
def get_train_symbol(backbone, neck, head): gt_bbox = X.var("gt_bbox") im_info = X.var("im_info") feat = backbone.get_rpn_feature() feat = neck.get_rpn_feature(feat) head.get_anchor() loss = head.get_loss(feat, gt_bbox, im_info) return X.group(loss)
def get_train_symbol(cls, backbone, neck, rpn_head): rpn_cls_label = X.var("rpn_cls_label") rpn_reg_target = X.var("rpn_reg_target") rpn_reg_weight = X.var("rpn_reg_weight") rpn_feat = backbone.get_rpn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rpn_loss = rpn_head.get_loss(rpn_feat, rpn_cls_label, rpn_reg_target, rpn_reg_weight) return X.group(rpn_loss)
def get_test_symbol(backbone, neck, head): im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") feat = backbone.get_rpn_feature() feat = neck.get_rpn_feature(feat) cls_score, bbox_xyxy = head.get_prediction(feat, im_info) return X.group([rec_id, im_id, im_info, cls_score, bbox_xyxy])
def get_test_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head): rec_id, im_id, im_info, proposal, proposal_score = \ FasterRcnn_TSD.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature_test(rcnn_feat, proposal) preds = bbox_head.get_prediction(proposal, roi_feat, rcnn_feat, im_info) return X.group([rec_id, im_id, im_info] + list(preds))
def get_test_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head, num_branch): rec_id, im_id, im_info, proposal, proposal_score = \ TridentFasterRcnn.get_rpn_test_symbol(backbone, neck, rpn_head, num_branch) im_info_branches = TridentResNetV2Builder.stack_branch_symbols( [im_info] * num_branch) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info_branches, proposal) cls_score = X.reshape(cls_score, (-3, -2)) bbox_xyxy = X.reshape(bbox_xyxy, (-3, -2)) if is_deploy: out = X.group([im_info, cls_score, bbox_xyxy]) else: out = X.group([rec_id, im_id, im_info, cls_score, bbox_xyxy]) return out
def get_rpn_test_symbol(cls, backbone, neck, rpn_head): if cls._rpn_output is not None: return cls._rpn_output im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") rpn_feat = backbone.get_rpn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) (proposal, proposal_score) = rpn_head.get_all_proposal(rpn_feat, im_info) cls._rpn_output = X.group([rec_id, im_id, im_info, proposal, proposal_score]) return cls._rpn_output
def get_test_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head): rec_id, im_id, im_info, proposal, proposal_score = \ DoublePredRcnn.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature_test(rcnn_feat, proposal) cls_score, bbox_xyxy, cls_sec_score, bbox_sec_xyxy = bbox_head.get_prediction( roi_feat, im_info, proposal) cls_score_concat = mx.sym.concat(*[cls_score, cls_sec_score], axis=1) bbox_xyxy_concat = mx.sym.concat(*[bbox_xyxy, bbox_sec_xyxy], axis=1) return X.group( [rec_id, im_id, im_info, cls_score_concat, bbox_xyxy_concat])
def get_rpn_test_symbol(cls, backbone, neck, rpn_head, num_branch): if cls._rpn_output is not None: return cls._rpn_output im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") rpn_feat = backbone.get_rpn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) im_info_branches = TridentResNetV2Builder.stack_branch_symbols([im_info] * num_branch) (proposal, proposal_score) = rpn_head.get_all_proposal(rpn_feat, im_info_branches) cls._rpn_output = X.group([rec_id, im_id, im_info, proposal, proposal_score]) return cls._rpn_output
def get_train_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head): gt_bbox = X.var("gt_bbox") im_info = X.var("im_info") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_head.get_anchor() rpn_loss = rpn_head.get_loss(rpn_feat, gt_bbox, im_info) proposal, bbox_cls, bbox_target, bbox_weight = rpn_head.get_sampled_proposal(rpn_feat, gt_bbox, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) return X.group(rpn_loss + bbox_loss)
def get_train_symbol(backbone, neck, head, kd_head): rpn_cls_label = X.var("rpn_cls_label") rpn_reg_target = X.var("rpn_reg_target") rpn_reg_weight = X.var("rpn_reg_weight") teacher_label = X.var("teacher_label") feat = backbone.get_rpn_feature() c2, c3, c4, c5 = feat feat_dict = {'c2': c2, 'c3': c3, 'c4': c4, 'c5': c5} feat = neck.get_rpn_feature(feat) loss = head.get_loss(feat, rpn_cls_label, rpn_reg_target, rpn_reg_weight) kd_loss = kd_head.get_loss(feat_dict, teacher_label) return X.group(loss + (kd_loss, ))
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, bbox_head): im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) proposal = rpn_head.get_all_proposal(rpn_feat, im_info) roi_feat = roi_extractor.get_roi_feature_test(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info, proposal) return X.group([rec_id, im_id, im_info, cls_score, bbox_xyxy])
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, mask_roi_extractor, bbox_head, mask_head, bbox_post_processor): rec_id, im_id, im_info, proposal, proposal_score = \ MaskFasterRcnn.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction(roi_feat, im_info, proposal) post_cls_score, post_bbox_xyxy, post_cls = bbox_post_processor.get_post_processing(cls_score, bbox_xyxy) mask_roi_feat = mask_roi_extractor.get_roi_feature(rcnn_feat, post_bbox_xyxy) mask = mask_head.get_prediction(mask_roi_feat) # mask score only for placeholder mask_score = mx.sym.full((1, ), -1, name='maskiou_prediction') return X.group([rec_id, im_id, im_info, post_cls_score, post_bbox_xyxy, post_cls, mask, mask_score])
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, bbox_head, \ bbox_head_2nd, bbox_head_3rd): im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) # stage1 proposal = rpn_head.get_all_proposal(rpn_feat, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal, "1st") _, bbox_xyxy = bbox_head.get_prediction(roi_feat, im_info, proposal) # stage2 proposal_2nd = bbox_xyxy roi_feat_2nd = roi_extractor.get_roi_feature(rcnn_feat, proposal_2nd, "2nd") _, bbox_xyxy_2nd = bbox_head_2nd.get_prediction( roi_feat_2nd, im_info, proposal_2nd) # stage3 proposal_3rd = bbox_xyxy_2nd roi_feat_3rd = roi_extractor.get_roi_feature(rcnn_feat, proposal_3rd, "3rd") cls_score_3rd, bbox_xyxy_3rd = bbox_head_3rd.get_prediction( roi_feat_3rd, im_info, proposal_3rd) # passing feature from stage3 through stage1's weight bbox_head.stage = "1st_3rd" cls_score_1st_3rd, _ = bbox_head.get_prediction(roi_feat_3rd, im_info) # passing feature from stage3 through stage2's weight bbox_head_2nd.stage = "2nd_3rd" cls_score_2nd_3rd, _ = bbox_head_2nd.get_prediction( roi_feat_3rd, im_info) # average score between [1st_3rd, 2nd_3rd, 3rd] import mxnet as mx cls_score_avg = mx.sym.add_n(cls_score_1st_3rd, cls_score_2nd_3rd, cls_score_3rd) / 3 return X.group([rec_id, im_id, im_info, cls_score_avg, bbox_xyxy_3rd])
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, bbox_head, num_branch): im_info = X.var("im_info") im_id = X.var("im_id") rec_id = X.var("rec_id") im_info_branches = TridentResNetV2Builder.stack_branch_symbols( [im_info] * num_branch) rpn_feat = backbone.get_rpn_feature() rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) proposal = rpn_head.get_all_proposal(rpn_feat, im_info_branches) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) cls_score, bbox_xyxy = bbox_head.get_prediction( roi_feat, im_info_branches, proposal) cls_score = X.reshape(cls_score, (-3, -2)) bbox_xyxy = X.reshape(bbox_xyxy, (-3, -2)) return X.group([rec_id, im_id, im_info, cls_score, bbox_xyxy])
def get_test_symbol(backbone, neck, rpn_head, roi_extractor, bbox_head, \ bbox_head_2nd, bbox_head_3rd): rec_id, im_id, im_info, proposal, proposal_score = \ CascadeRcnn.get_rpn_test_symbol(backbone, neck, rpn_head) rcnn_feat = backbone.get_rcnn_feature() rcnn_feat = neck.get_rcnn_feature(rcnn_feat) # stage1 roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) _, bbox_xyxy = bbox_head.get_prediction(roi_feat, im_info, proposal) # stage2 proposal_2nd = bbox_xyxy roi_feat_2nd = roi_extractor.get_roi_feature(rcnn_feat, proposal_2nd) _, bbox_xyxy_2nd = bbox_head_2nd.get_prediction( roi_feat_2nd, im_info, proposal_2nd) # stage3 proposal_3rd = bbox_xyxy_2nd roi_feat_3rd = roi_extractor.get_roi_feature(rcnn_feat, proposal_3rd) cls_score_3rd, bbox_xyxy_3rd = bbox_head_3rd.get_prediction( roi_feat_3rd, im_info, proposal_3rd) # passing feature from stage3 through stage1's weight bbox_head.stage = "1st_3rd" cls_score_1st_3rd, _ = bbox_head.get_prediction(roi_feat_3rd, im_info) # passing feature from stage3 through stage2's weight bbox_head_2nd.stage = "2nd_3rd" cls_score_2nd_3rd, _ = bbox_head_2nd.get_prediction( roi_feat_3rd, im_info) # average score between [1st_3rd, 2nd_3rd, 3rd] cls_score_avg = mx.sym.add_n(cls_score_1st_3rd, cls_score_2nd_3rd, cls_score_3rd) / 3 return X.group([rec_id, im_id, im_info, cls_score_avg, bbox_xyxy_3rd])
def get_train_symbol(cls, backbone, neck, rpn_head, roi_extractor, bbox_head, kd_head): gt_bbox = X.var("gt_bbox") im_info = X.var("im_info") teacher_label = X.var("teacher_label") rpn_feat = backbone.get_rpn_feature() c2, c3, c4, c5 = rpn_feat feat_dict = {'c2': c2, 'c3': c3, 'c4': c4, 'c5': c5} rcnn_feat = backbone.get_rcnn_feature() rpn_feat = neck.get_rpn_feature(rpn_feat) rcnn_feat = neck.get_rcnn_feature(rcnn_feat) rpn_head.get_anchor() rpn_loss = rpn_head.get_loss(rpn_feat, gt_bbox, im_info) proposal, bbox_cls, bbox_target, bbox_weight = rpn_head.get_sampled_proposal( rpn_feat, gt_bbox, im_info) roi_feat = roi_extractor.get_roi_feature(rcnn_feat, proposal) bbox_loss = bbox_head.get_loss(roi_feat, bbox_cls, bbox_target, bbox_weight) kd_loss = kd_head.get_loss(feat_dict, teacher_label) return X.group(rpn_loss + bbox_loss + (kd_loss, ))