Skip to content

Commit dc57198

Browse files
author
yixu.cui
committed
add a tool to convert MOT20 data to yolo
1 parent d26f4b5 commit dc57198

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

tools/convert_MOT20_to_yolo.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import glob
1111
import numpy as np
1212
import random
13+
import shutil
1314

1415
from tqdm import tqdm
1516

1617
# DATA_ROOT = '/data/wujiapeng/datasets/MOT20/'
17-
DATA_ROOT = "/perception/yixu.cui/datas/tracking/MOT20"
18+
# DATA_ROOT = "/perception/yixu.cui/datas/tracking/MOT20"
19+
DATA_ROOT = "/share-global/yixu.cui/datas/tracking/MOT20"
1820
image_wh_dict = {} # seq->(w,h) 字典 用于归一化
1921

2022

@@ -123,6 +125,21 @@ def process_train_test(
123125
osp.join(img_src_root, img_name),
124126
link_name,
125127
) # 创建软链接
128+
else:
129+
img_link_root = osp.join(
130+
DATA_ROOT, "images", split, seq
131+
) # 该序列图片存储位置
132+
133+
if not osp.exists(img_link_root):
134+
os.makedirs(img_link_root, exist_ok=True)
135+
136+
link_name = osp.join(img_link_root, img_name)
137+
if not osp.exists(link_name):
138+
# print(link_name)
139+
shutil.copy2(
140+
osp.join(img_src_root, img_name),
141+
link_name,
142+
) # 创建软链接
126143

127144
# 第二步 产生真值(gt)文件
128145
# print('step2, generating gt files...')
@@ -193,10 +210,26 @@ def process_train_test(
193210
osp.join(img_src_root, img_name),
194211
link_name,
195212
) # 创建软链接
213+
else:
214+
img_link_root = osp.join(
215+
DATA_ROOT, "images", split, seq
216+
) # 该序列图片存储位置
217+
218+
if not osp.exists(img_link_root):
219+
os.makedirs(img_link_root, exist_ok=True)
220+
221+
link_name = osp.join(img_link_root, img_name)
222+
print(link_name)
223+
if not osp.exists(link_name):
224+
print(link_name)
225+
shutil.copy2(
226+
osp.join(img_src_root, img_name),
227+
link_name,
228+
) # 创建软链接
196229

197230
# 第三步 产生图片索引train.txt, test.txt等
198231
print(f"generating img index file of {seq}")
199-
to_file = os.path.join("./datasets/mot20", split + ".txt")
232+
to_file = os.path.join(opts.local_dataset_dir, split + ".txt")
200233
with open(to_file, "a") as f:
201234
for idx, img in enumerate(imgs):
202235
if idx < int(seq_length * frame_range["start"]) or idx > int(
@@ -209,11 +242,13 @@ def process_train_test(
209242

210243

211244
if __name__ == "__main__":
212-
if not osp.exists("./datasets/mot20"):
213-
os.makedirs("./datasets/mot20")
245+
local_dataset_dir = "./datasets/mot20_sg"
246+
if not osp.exists(local_dataset_dir):
247+
os.makedirs(local_dataset_dir, exist_ok=True)
214248

215249
parser = argparse.ArgumentParser()
216-
parser.add_argument('--split', type=str, default='train', help='train, test, val or val_dpm')
250+
parser.add_argument('--local_dataset_dir', type=str, default=local_dataset_dir, help='to save datasets file and cache')
251+
parser.add_argument('--split', type=str, default='train', help='train, test, val, train_overlap or val_dpm')
217252
parser.add_argument('--generate_imgs', action='store_true', help='whether generate soft link of imgs')
218253
parser.add_argument('--certain_seqs', action='store_true', help='for debug')
219254
parser.add_argument('--half', action='store_true', help='half frames')

0 commit comments

Comments
 (0)