YOLOv8训练MOT17
数据准备
1.制作训练数据
将MOT17分割为image和label两个子文件,两个子文件夹分别放test、train、val。
convert.py将数据集分割,该文件放在MOT17路径下。
'''
创建以下四个目录,用于存放图片和标签
images/train
images/val
labels/train
labels/val
'''
import os
import shutil
import numpy as np
import configparser
if not os.path.exists('images'):
os.makedirs('images/train')
os.makedirs('images/val')
os.makedirs('images/test')
if not os.path.exists('labels'):
os.makedirs('labels/train')
os.makedirs('labels/val')
os.makedirs('labels/test')
def convert(imgWidth, imgHeight, left, top, width, height):
x = (left + width / 2.0) / imgWidth
y = (top + height / 2.0) / imgHeight
w = width / imgWidth
h = height / imgHeight
return ('%.6f'%x, '%.6f'%y, '%.6f'%w, '%.6f'%h) # 保留6位小数
for mot_dir in os.listdir('train'): # mot_dir是例如MOT17-02-FRCNN这种
det_path = os.path.join('train', mot_dir, 'det/det.txt') # det.txt路径
dets = np.loadtxt(det_path, delimiter=',') # 读取det.txt文件
ini_path = os.path.join('train', mot_dir, 'seqinfo.ini') # seqinfo.ini路径
conf = configparser.ConfigParser()
conf.read(ini_path) # 读取seqinfo.ini文件
seqLength = int(conf['Sequence']['seqLength']) # MOT17-02-FRCNN序列的长度
imgWidth = int(conf['Sequence']['imWidth']) # 图片宽度
imgHeight = int(conf['Sequence']['imHeight']) # 图片长度
for det in dets:
frame_id, _, left, top, width, height = int(det[0]), det[1], det[2], det[3], det