Towards-Realtime-MOT
Towards-Realtime-MOT copied to clipboard
how to format the training daaset
As i use the MOT17 dataset, but the original data from official website have a different instruction with yours described in data zoo, so, how can i convert it?
Run this code. It will require some arguments as mentioned in the top of the code.
"""
Arguments-
1st->file/path/to/gt.txt
2nd->file/path/to/first/image/of/seq.jpg
3rd->folder/path/to/put/result/files
"""
import csv
import sys
import cv2
def tlwh_to_cxcywh(x, y, w, h):
cx=x+w/2
cy=y+h/2
return cx, cy, w, h
def normalize(x, y, w, h, img_h, img_w):
nx=x/img_w
ny=y/img_h
nw=w/img_w
nh=h/img_h
return nx, ny, nw, nh
img_h, img_w, _=cv2.imread(sys.argv[2]).shape
with open(sys.argv[1], 'r') as file:
reader = csv.reader(file)
ini=0
for row in reader:
if int(row[6]) == 0:
continue
if ini!=row[0]:
intt=int(row[0])
msg = sys.argv[3]+f'/{intt:06d}.txt'
f=open(msg, "a+")
writer=csv.writer(f, delimiter=' ')
cx, cy, w, h=tlwh_to_cxcywh(float(row[2]), float(row[3]), float(row[4]), float(row[5]))
nx, ny, nw, nh=normalize(cx, cy, w, h, img_h, img_w)
wrow=[str(0), str(int(row[1])-1), str(nx), str(ny), str(nw), str(nh)]
writer.writerow(wrow)
ok, thanks for your code, i will have a try.