用Yolact模型训练自己的数据集

1.首先用labelme标注数据(分割法)

2.yolact训练的数据集为coco数据集,所以要转化数据集,使用从Git下载的labelme项目中的labelme2coco转换就可以

这里因为我的标注里有circle,刚开始训练总是失败报错,因为多边形标注至少要四个点的信息,labelme2coco中需要增加一段让它支持圆形标注

 Git中有解决方法https://github.com/wkentaro/labelme/issues/537

这里也放出增加的一段代码(Git里的方法)

            elif shape_type == "circle":

                # Create polygon shaped based on connecting lines from/to following degress
                bearing_angles = [0, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165,
                180, 195, 210, 225, 240, 255, 270, 285, 300, 315, 330, 345, 360]

                orig_x1 = points[0][0]
                orig_y1 = points[0][1]

                orig_x2 = points[1][0]
                orig_y2 = points[1][1]

                # Calculate radius of circle
                cx = (orig_x2 - orig_x1)**2
                cy = (orig_y2 - orig_y1)**2
                radius = math.sqrt(cx + cy)

                circle_polygon = []

                for i in range(0, len(bearing_angles) - 1):
                    ad1 = math.radians(bearing_angles[i])
                    x1 = radius * math.cos(ad1)
                    y1 = radius * math.sin(ad1)
                    circle_polygon.append((orig_x1 + x1, orig_y1 + y1))

                    ad2 = math.radians(bearing_angles[i+1])
                    x2 = radius * math.cos(ad2)
                    y2 = radius * math.sin(ad2)
                    circle_polygon.append((orig_x1 + x2, orig_y1 + y2))

                points = circle_polygon
            else:
                points = np.asarray(points).flatten().tolist()

            segmentations[instance].append(points)
        segmentations = dict(segmentations)

我自己的凑点方法:

 

转换好的coco数据集格式:

2.下载yolact模型,根据给出的网址下载权重文件,放在weights文件夹下,有一个没给出来,自己去网上找地址下载

 3.修改config.py

(1) 类别,类别的数量

(2)修改数据集地址dataset_base,不想分配验证集可以写和train一样地址

 (3)修改coco_base_config和yolact_base_config

      yolact_base_config中的max_iter是控制训练轮数的,batch-size为1,图片数量为100张,max_iter=2500时会训练两百轮 

 3.训练

python train.py --config=yolact_base_config --batch_size=1 --validation_epoch=-1

 4.测试,这里可以用中断的模型也可以用完整训练的模型

python eval.py --trained_model=weights/yolact_base_28_2844_interrupt.pth --score_threshold=0.15 --top_k=15 --image=testP.jpg --c
onfig=yolact_base_config --display

  • 4
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值