首页 > 其他分享 >bdd100k数据集制作用于YOLOv3训练

bdd100k数据集制作用于YOLOv3训练

时间:2022-11-22 13:32:16浏览次数:31  
标签:box bdd100k obj 训练 min json result YOLOv3 append


bdd100k数据集制作用于YOLOv3训练_bdd100k


这篇博文主要记录了将bdd100k数据集整理成yolo模型的要求来训练。这里的数据格式并非官网的darknet格式,而是一般的模型格式:

  1. 以图片名作为TXT名称
  2. 将同一幅图中的label和对应的bounding box整理在同一个txt中。

bdd100k数据集介绍

1.Annotations

1、 道路目标边界框:10万张图片,其中:训练集7万,测试集2万,验证集1万

2、 可行驶区域:10万张图片

3、 车道线标记:10万张图片

4、 全帧实例分割:1万张图片

Annotation包含了被标记对象的源图像的URL、类别标签、大小(起始坐标、结束坐标、宽度和高度)、截断、遮挡和交通灯颜色等信息。

bdd100k数据集制作用于YOLOv3训练_数据集_02

json文件解析(转换成YOLO数据集格式)

转换code

import json
#数据集中包含的10个类别
categorys = ['car', 'bus', 'person', 'bike', 'truck', 'motor', 'train', 'rider', 'traffic sign', 'traffic light']

# 图片的分辨率
picture_width = 1282
picture_height = 720

def parseJson(jsonFile):
'''
params:
jsonFile -- BDD00K数据集的一个json标签文件
return:
返回一个列表的列表,存储了一个json文件里面的方框坐标及其所属的类,
'''
objs = []
obj = []
info = jsonFile
name = info['name']
objects = info['labels']
for i in objects:
if(i['category'] in categorys):
obj.append(int(i['box2d']['x1']))
obj.append(int(i['box2d']['y1']))
obj.append(int(i['box2d']['x2']))
obj.append(int(i['box2d']['y2']))
obj.append(i['category'])
objs.append(obj)
obj = []
return name, objs

#test
file_handle = open('traindata.txt', mode='a')
f = open("/home/violet/Documents/dataset/bdd100k/label/train/bdd100k_labels_images_train.json") # json文件的绝对路径,换成自己的
info = json.load(f)
objects = info
n = len(objects)

# 将左上右下坐标转换成 中心x,y以及w h
def bboxtrans(box_x_min, box_y_min, box_x_max, box_y_max):
x_center = (box_x_min + box_x_max) / (2 * picture_width)
y_center = (box_y_min + box_y_max) / (2 * picture_height)
width = (box_x_max - box_x_min) / (2 * picture_width)
height = (box_y_max - box_y_min) / (2 * picture_height)
return x_center, y_center, width, height



for i in range(n):
an = ""
name, result = parseJson(objects[i])
an = "./data/custom/images/train/" + name # 这里我改成了图片的相对路径
for j in range(len(result)):
cls_id = categorys.index(result[j][4])
x, y, w, h = bboxtrans(result[j][0], result[j][1], result[j][2], result[j][3])
an = an + ' ' +str(cls_id) + ' '+str(x)+' '+str(y)+' '+str(w)+' '+str(h)
an = an + '\n'
file_handle.write(an)
print(len(result))
print(an)

数据整合code

with open('traindata.txt') as f:
line = f.readline()
while (line):
data = line.strip().split() # strip(): 删除前后空格、空行
wf = open('./data/' + data[0][27:-4]+'.txt', 'a+')
numofline = len(data) - 1
for i in range(1, numofline, 5):
for j in range(0, 5):
idx = i + j
wf.write(data[idx]) # class_index center_x cnter_y w h
wf.write(' ')
wf.write('\n')
line = f.readline()


标签:box,bdd100k,obj,训练,min,json,result,YOLOv3,append
From: https://blog.51cto.com/u_13875041/5877870

相关文章