Towards-Realtime-MOT icon indicating copy to clipboard operation
Towards-Realtime-MOT copied to clipboard

how to format the training daaset

Open wangxianrui opened this issue 5 years ago • 2 comments

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?

wangxianrui avatar Feb 29 '20 07:02 wangxianrui

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)
        

PartheshSoni avatar Mar 03 '20 06:03 PartheshSoni

ok, thanks for your code, i will have a try.

wangxianrui avatar Mar 03 '20 06:03 wangxianrui