팀 프로젝트 진행

  • WBF(weighted_boxes_fusion) 구현

    • Ensemble 시 가장 높은 confident의 바운딩 박스 1개만 사용하는 NMS, Soft-NMS와 달리, 최대 3개를 사용해 안전하게 바운딩 박스를 잡는 WBF 방식이 성능이 높다고 확인해 구현함. 함수 자체는 오픈 소스로 구현되어 있었지만, 함수가 받는 인자들이 mmdetection의 output 형식과 많이 달라서 꼼꼼히 파악한 뒤 매끄럽게 호환되도록 하는 부분을 위주로 구현해야 했다. 완성 후 임의로 두 모델을 사용해 ensemble을 진행해본 결과 더 높은 점수의 모델보다 높은 점수를 냈다. (앞으로 팀원들이 학습한 best 모델들을 ensemble 시 이용할 예정)

        prediction_strings = []
        file_names = []
        coco = COCO(cfg.data.test.ann_file)
        imag_ids = coco.getImgIds()
        img_size = 512.
      
        weights = [2, 1] # ensemble weights for model 1 and model 2
        iou_thr = 0.6
        skip_box_thr = 0.0001
      
        for idx in tqdm(range(len(output1))):
                  
            boxes_list1, boxes_list2, boxes_list = [], [], []
            scores_list1, scores_list2, scores_list = [], [], []
            labels_list1, labels_list2, labels_list = [], [], []
                  
            # model 1
            for label, boxes_in_label in enumerate(output1[idx]):
                for box_and_score in boxes_in_label:
                    scores_list1.append(box_and_score[4])
                    boxes_list1.append(box_and_score[:4] / img_size)
                    labels_list1.append(label)
                  
            # model 2
            for label, boxes_in_label in enumerate(output2[idx]):
                for box_and_score in boxes_in_label:
                    scores_list2.append(box_and_score[4])
                    boxes_list2.append(box_and_score[:4] / img_size)
                    labels_list2.append(label)
                  
            boxes_list = [boxes_list1, boxes_list2]
            scores_list = [scores_list1, scores_list2]
            labels_list = [labels_list1, labels_list2]
                  
            boxes, scores, labels = weighted_boxes_fusion(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
                  
            prediction_string = ''
            image_info = coco.loadImgs(coco.getImgIds(imgIds=idx))[0]
                  
            for i, box in enumerate(boxes):
                prediction_string += str(int(labels[i])) + ' ' + str(scores[i])[:11] + ' ' + str(box[0]*img_size)[:9] + ' '  + str(box[1]*img_size)[:9] + ' '  + str(box[2]*img_size)[:9] + ' '  + str(box[3]*img_size)[:9] + ' '
            prediction_strings.append(prediction_string)
            file_names.append(image_info['file_name'])
      
        submission = pd.DataFrame()
        submission['PredictionString'] = prediction_strings
        submission['image_id'] = file_names
        submission.to_csv(os.path.join(cfg.work_dir, f'submission_wbf_ensemble.csv'), index=None)
      
    • 구현한 WBF를 적용해 성능 향상

      • 종호님이 학습한 모델 2개 (resnext101/FPN/Cascade-RCNN) WBF를 통해 앙상블
        • 모델 1 (NMS): 0.4640
        • 모델 2 (NMS): 0.4658
        • WBF 앙상블 결과: 0.4896