poly-yolo训练自己的数据

项目地址:poly-yolo
论文地址:poly-yolo论文

1、 Format of data for training

Generally, YOLO uses notation of one image per line. One line includes all the boxes inside an image.

path_to\image1.jpg x1,y1,x2,y2,class,p1x,p1y,pnx,pny x1,y1,x2,y2,class,p1x,p1y,pnx,pny
path_to\image2.jpg x1,y1,x2,y2,class,p1x,p1y,pnx,pny

Where x1,y1 denote top-left of a bounding box and x2,y2 denote bottom-right. p1x,p1y … pnx,pny are coordinates of bounding box vertices.
Script labels_to_yolo_format.py converts IDD and Cityscapes dataset annotations to yolo format. The generated annotation file is put to the provided image folder. Use ‘–help’ for script parameters description.

2、 训练网络结构

2.1 首先需要准备数据集。

我们将coco的 val2014数据集转成poly-yolo需要的数据集,脚本如下。将val2014的coco数据集通过下面数据集转换之后就可以得到一个train.txt存储这我们需要的训练标签。标签格式(path_to\image1.jpg x1,y1,x2,y2,class,p1x,p1y,pnx,pny x1,y1,x2,y2,class,p1x,p1y,pnx,pny)

import json
from collections import defaultdict
 
name_box_id = defaultdict(list)
name_segmentation_id = defaultdict(list)
id_name = dict()
f = open(
    "instances_val2014.json",
    encoding='utf-8')
data = json.load(f)
 
annotations = data['annotations']
for ant in annotations:
    id = ant['image_id']
    name = 'coco/train2014/COCO_val2014_%012d.jpg' % id
    cat = ant['category_id']
 
    if cat >= 1 and cat <= 11:
        cat = cat - 1
    elif cat >= 13 and cat <= 25:
        cat = cat - 2
    elif cat >= 27 and cat <= 28:
        cat = cat - 3
    elif cat >= 31 and cat <= 44:
        cat = cat - 5
    elif cat >= 46 and cat <= 65:
        cat = cat - 6
    elif cat == 67:
        cat = cat - 7
    elif cat == 70:
        cat = cat - 9
    elif cat >= 72 and cat <= 82:
        cat = cat - 10
    elif cat >= 84 and cat <= 90:
        cat = cat - 11
 
    name_box_id[name].append([ant['bbox'], cat,ant['segmentation']])
 
f = open('train.txt', 'w')
for key in name_box_id.keys():
    f.write(key)
    box_infos = name_box_id[key]
 
    for info in box_infos:
        x_min = int(info[0][0])
        y_min = int(info[0][1])
        x_max = x_min + int(info[0][2])
        y_max = y_min + int(info[0][3])
        box_info = " %d,%d,%d,%d,%d," % (
            x_min, y_min, x_max, y_max, int(info[1]))
        #print(info[2])
        #print('*********************************')
        if isinstance(info[2],list):
            if len(info[2])==1:
                f.write(box_info)
                lista = []
                for i in info[2][0]:
                    i = int(i)
                    lista.append(i)
                f.write(str(lista))      
    f.write('\n')
f.close()

2.2将calss类别修改成coco的80类别,运行训练模型。

python poly-yolo.py

网络就开始训练了。

参考:将POLY-YOLO代码跑起来的环境配置,poly-yolo训练自己的数据集

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落花逐流水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值