-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdemo_tadt.py
53 lines (48 loc) · 2.13 KB
/
demo_tadt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#tadt-demo
import glob
from os.path import join, realpath, dirname
import numpy as np
import scipy.io
from tadt_tracker import Tadt_Tracker
from backbone_v2 import build_vgg16
def load_sequece(root_path):
img_list = (glob.glob(join(root_path, '*/img/*.jpg')))
img_list.sort()
gt_path = glob.glob(join(root_path, '*/*.txt'))
with open(gt_path[0], 'r') as f:
gt_bboxes = f.readlines()
if '\t' in gt_bboxes[0]:
spl = '\t'
else:
spl = ','
gt_bboxes = np.array([list(map(int,gt_bbox.strip('\n').split(spl))) for gt_bbox in gt_bboxes]).astype(int)
return img_list, gt_bboxes
if __name__ == "__main__":
from defaults import _C as cfg
import time
import torch
assert(False), 'please download "imagenet-vgg-verydeep-16.mat" from "http://www.vlfeat.org/matconvnet/models/imagenet-vgg-verydeep-16.mat" and set its path in defaults.py'
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
root_path = join(realpath(dirname(__file__)),'sequences/')
img_list, gt_bboxes = load_sequece(root_path)
#------------------demo------------------------------------------------------------------
model = build_vgg16(cfg)
tracker = Tadt_Tracker(cfg, model = model, device = device, display = True)
tracker.initialize_tadt(img_list[0], gt_bboxes[0])
#if want to visualize the selected feature, uncomment these lines
#tracker.visualize_feature(
# features = tracker.features,
# stage = 'conv4_3',
# srch_window_size = (180,180),
# subwindow = tracker.subwindow,
# feature_weights = tracker.feature_weights,
# balance_weights = tracker.balance_weights
# )
for i in range(1, len(img_list)):
tracker.tracking(img_list[i], i)
print('fps: ',tracker.cal_fps(i))
#name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
#with open(root_path+name+'.txt','w') as f:
# for bbox in results:
# newline = str(bbox) + '\n'
# f.write(newline)