栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

kaggle实战:海星赛复盘

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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%的成绩

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/744414.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号