poly-yolo训练自己的数据
項(xiàng)目地址: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,pnyWhere 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、 訓(xùn)練網(wǎng)絡(luò)結(jié)構(gòu)
2.1 首先需要準(zhǔn)備數(shù)據(jù)集。
我們將coco的 val2014數(shù)據(jù)集轉(zhuǎn)成poly-yolo需要的數(shù)據(jù)集,腳本如下。將val2014的coco數(shù)據(jù)集通過下面數(shù)據(jù)集轉(zhuǎn)換之后就可以得到一個(gè)train.txt存儲(chǔ)這我們需要的訓(xùn)練標(biāo)簽。標(biāo)簽格式(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 defaultdictname_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' % idcat = ant['category_id']if cat >= 1 and cat <= 11:cat = cat - 1elif cat >= 13 and cat <= 25:cat = cat - 2elif cat >= 27 and cat <= 28:cat = cat - 3elif cat >= 31 and cat <= 44:cat = cat - 5elif cat >= 46 and cat <= 65:cat = cat - 6elif cat == 67:cat = cat - 7elif cat == 70:cat = cat - 9elif cat >= 72 and cat <= 82:cat = cat - 10elif cat >= 84 and cat <= 90:cat = cat - 11name_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類別,運(yùn)行訓(xùn)練模型。
python poly-yolo.py網(wǎng)絡(luò)就開始訓(xùn)練了。
參考:將POLY-YOLO代碼跑起來的環(huán)境配置,poly-yolo訓(xùn)練自己的數(shù)據(jù)集
總結(jié)
以上是生活随笔為你收集整理的poly-yolo训练自己的数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AC米兰2-1胜利物浦夺冠 巨星pipp
- 下一篇: Cesium地下管线信息系统(视频)