kaggle实战:海星赛复盘

赛题背景:

本次比赛的目标是通过建立一个在珊瑚礁水下视频上训练的物体检测模型,实时准确地识别海星。

比赛方案:

工具库:mmdetection,yolov5

开源代码链接:the framework of ensemble | Kaggle

比赛最终的方案是fasterrcnn和yolov5通过wbf模型融合

定义模型

config_file = f'../input/fastrcnn2000/faster_rcnn_cbv2d1_r50_fpn_1x_coco.py'
checkpoint_file = '../input/faster-rcnn/faster_rcnn_cbv2/epoch_8.pth' 
m1 = init_detector(config_file, checkpoint_file, device='cuda:0')
m2 = torch.hub.load('../input/yolov5-lib-ds', 
                       'custom', 
                       path='../input/yolov5s6/f2_sub2.pt',
                       source='local',
                       force_reload=True)  # local repo
m2.conf = 0.48

wbf示例代码

def wbf_one_img_result(result_cbnet, result_yolo, IOU_WBF=0.2):
    boxes_list = [[],[]]
    scores_list = [[], []]
    labels_list = [[], []]
    weights = [1, 1]
    iou_thr = 0.5
    skip_box_thr = 0.3
    #sigma = 0.1
    for cbnet in result_cbnet[0]:
        x1, y1, x2, y2, conf = cbnet
        boxes_list[0].append([x1/1280, y1/720, x2/1280, y2/720])
        scores_list[0].append(conf)
        labels_list[0].append(0)
for idx, row in result_yolo.pandas().xyxy[0].iterrows():
        boxes_list[1].append([row.xmin/1280, row.ymin/720, row.xmax/1280, row.ymax/720])
        scores_list[1].append(row.confidence)
        labels_list[1].append(0)
    
    boxes, scores, labels = weighted_boxes_fusion(boxes_list, scores_list, labels_list, weights=weights, iou_thr=iou_thr, skip_box_thr=skip_box_thr)
    
    length = len(scores)
    res = ''
    for idx in range(length):
        conf = scores[idx]
        xmin, ymin, xmax, ymax = boxes[idx]
        if conf > 0.4:
            res += f'{conf} {xmin*1280} {ymin*720} {(xmax-xmin)*1280} {(ymax-ymin)*720} '
    return res.strip(' ')


上分技巧:

1.加大分辨率:提高yolo输入图片的size可以提高模型的性能

2.工具库:ensemble-boxes

比赛总结:

最终获得前2%的成绩

你可能感兴趣的:(深度学习,比赛模板代码,深度学习,pytorch,人工智能)