计划使用MOT16数据集做基于ConvLSTM的目标检测,其标注数据在gt.txt中,第8列为分类,有以下12类
-
Pedestrian(行人)------主要目标,要跟踪
-
Person on vehicle(车上的人)
-
Car(轿车)
-
Bicycle(自行车)
-
Motorbike(摩托车)
-
Non motorized vehicle(非机动车)
-
Static person(静止的人)
-
Distractor(干扰物)
-
Occluder(遮挡物)
-
Occluder on the ground(地面遮挡物)
-
Occluder full(完全遮挡)
-
Reflection(倒影)
下面代码把1/2/7合并为1类,把3作为2类,把4/5合并为3类,其他的全部不要,生成new_gt.txt
python
import os
import numpy as np
mot16_root = "MOT16/train"
seqs = [d for d in os.listdir(mot16_root) if os.path.isdir(os.path.join(mot16_root, d))]
for seq in seqs:
gt_path = os.path.join(mot16_root, seq, "gt/gt.txt")
out_path = os.path.join(mot16_root, seq, "gt/new_gt.txt")
if not os.path.exists(gt_path):
continue
data = np.loadtxt(gt_path, delimiter=',')
new_data = []
for row in data:
cls = int(row[7])
if cls in [1, 2, 7]:
row[7] = 1
new_data.append(row)
elif cls == 3:
row[7] = 2
new_data.append(row)
elif cls in [4, 5]:
row[7] = 3
new_data.append(row)
if new_data:
np.savetxt(out_path, np.array(new_data), fmt='%.6g', delimiter=',')
print(f"Saved: {out_path}")