最近想跑大佬Bubbliiiing复现的目标检测算法,但是大佬用的是voc格式的数据集,给的数据集转换代码也是针对voc数据集的,我之前用的是yolov5的,不能直接用,就自己写了一个
效果如下
import os
import cv2
import numpy as np
def txt2array(txt_path, delimiter):
# 功能:读取只包含数字的txt文件,并转化为array形式
# txt_path:txt的路径
# delimiter:数据之间的分隔符
data_list = []
with open(txt_path) as f:
data = f.readlines()
for line in data:
line = line.strip("\n") # 去除末尾的换行符
data_split = line.split(delimiter)
temp = list(map(float, data_split))
data_list.append(temp)
data_array = np.array(data_list)
return data_array
def xywh2xyxy_cls(x):
# Convert nx4 boxes from [x, y, w, h] to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
y = np.copy(x)
# y[:, 0] = x[:, 0] # class
y[:, 1] = x[:, 1] - x[:, 3] / 2 # top left x
y