赞
踩
使用DarkLabel
制作目标追踪数据集,在训练模型时需要用到MOT数据集
格式,因此需要进行格式转换
。
参考pprpp大神的文章:https://www.jianshu.com/p/f36a45236044
先说区别:时间太长,我已经忘记了许多,似乎记得pprpp大神的代码应该是多个文件夹下的自动转换,而这里的代码是手动进行每个子文件夹的转换。pprpp大神的应该是单类别转换,这里的是多类别转换
。
import os ''' (1)区别如下: dir_dl_gt.txt(转换前) frame(从0开始计), 数量, id(从0开始), box(x1,y1,x2,y2), class=null 0,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null 1,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null 2,4,0,450,194,558,276,null,1,408,147,469,206,null,2,374,199,435,307,null,3,153,213,218,314,null ----------------------------------------------------------------------------------------------- gt.txt(转换后) frame(从1开始计), id(从1开始计), box(left top w, h),ignore=1(不忽略), class=1(从1开始),覆盖=1), 1,1,1363,569,103,241,1,1,0.86014 2,1,1362,568,103,241,1,1,0.86173 3,1,1362,568,103,241,1,1,0.86173 4,1,1362,568,103,241,1,1,0.86173 (2)类别信息: class1,class2,class3,class4,class5为追踪目标的类别 ''' def xyxy2xywh(x): # Convert bounding box format from [x1, y1, x2, y2] to [x, y, w, h] # y = torch.zeros_like(x) if isinstance(x, # torch.Tensor) else np.zeros_like(x) y = [0, 0, 0, 0] y[0] = (x[0] + x[2]) / 2 y[1] = (x[1] + x[3]) / 2 y[2] = x[2] - x[0] y[3] = x[3] - x[1] return y def process_darklabel(video_label_path, mot_label_path): f = open(video_label_path, "r") f_o = open(mot_label_path, "w") contents = f.readlines() for line in contents: line = line[:-1] num_list = [num for num in line.split(',')] frame_id = int(num_list[0]) + 1 # 帧id total_num = int(num_list[1]) # 图片中的目标个数 base = 2 # 从2开始 for i in range(total_num): # 多个目标 _id = int(num_list[base + i * 6]) + 1 _box_x1 = int(num_list[base + i * 6 + 1]) _box_y1 = int(num_list[base + i * 6 + 2]) _box_x2 = int(num_list[base + i * 6 + 3]) _box_y2 = int(num_list[base + i * 6 + 4]) y = xyxy2xywh([_box_x1, _box_y1, _box_x2, _box_y2]) classname_str = num_list[base + i * 6 + 5] # 多类别多目标追踪,帧id和fairmot一样从1开始,类别id从0开始 if(classname_str=="class1"): class_index = 0 elif(classname_str=="class2"): class_index = 1 elif(classname_str=="class3"): class_index = 2 elif (classname_str == "class4"): class_index = 3 elif (classname_str == "class5"): class_index = 4 else: class_index = 5 print('warning:文件中存在未识别的类别信息——',classname_str) write_line = "%d,%d,%d,%d,%d,%d,1,%d,1\n" % (frame_id, _id, y[0], y[1], y[2], y[3], int(class_index)) f_o.write(write_line) f.close() f_o.close() if __name__ == "__main__": root_dir = "./path/work/" # 图片文件所在文件夹 video_label_path = os.path.join(root_dir, "VID10_dl_gt.txt") # darklabel标注保存文件 mot_label_path = os.path.join(root_dir, "gt.txt") # 生成的mot标注文件 process_darklabel(video_label_path, mot_label_path)
将转换得到的gt.txt文件放到gt文件夹中;
img1中方放图片,记得删除dir_dl_gt.txt文件(darklabel标注文件);
seqinfo.ini文件保存的是该文件夹的信息,各种信息按照个人理解如下图所示;
det文件夹先不用管,我一般将darklabel标注文件放到这里,具体的MOT数据集格式讲解可自行百度。
PS:鼠标坏了总是连击,好几次截图在编辑过程中就跟确认了(QQ截图,双击完成),没有好好排版,各位别嫌弃丑啊 -_-| 。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。