66
77import cv2
88import time as time
9- from util import cxy_wh_2_rect1 , rect1_2_cxy_wh , gaussian_shaped_labels , cxy_wh_2_bbox
9+ from util import crop_chw , gaussian_shaped_labels , cxy_wh_2_rect1 , rect1_2_cxy_wh , cxy_wh_2_bbox
1010from net import DCFNet
11- from sample import resample
1211from eval_otb import eval_auc
1312
1413
@@ -19,7 +18,7 @@ class TrackerConfig(object):
1918 crop_sz = 125
2019
2120 lambda0 = 1e-4
22- padding = 2.0
21+ padding = 2
2322 output_sigma_factor = 0.1
2423 interp_factor = 0.01
2524 num_scale = 3
@@ -34,7 +33,7 @@ class TrackerConfig(object):
3433 net_average_image = np .array ([104 , 117 , 123 ]).reshape (- 1 , 1 , 1 ).astype (np .float32 )
3534 output_sigma = crop_sz / (1 + padding ) * output_sigma_factor
3635 y = gaussian_shaped_labels (output_sigma , net_input_size )
37- yf = torch .rfft (torch .Tensor (y ).view (1 , 1 , crop_sz , crop_sz ).cuda (), signal_ndim = 2 , normalized = False )
36+ yf = torch .rfft (torch .Tensor (y ).view (1 , 1 , crop_sz , crop_sz ).cuda (), signal_ndim = 2 )
3837 cos_window = torch .Tensor (np .outer (np .hanning (crop_sz ), np .hanning (crop_sz ))).cuda ()
3938
4039
@@ -56,8 +55,7 @@ def __init__(self, im, init_rect, config=TrackerConfig(), gpu=True):
5655 # crop template
5756 window_sz = target_sz * (1 + config .padding )
5857 bbox = cxy_wh_2_bbox (target_pos , window_sz )
59- patch = resample (im , bbox , config .net_input_size , [0 , 0 , 0 ])
60- # cv2.imwrite('crop.jpg', np.transpose(patch[::-1,:,:], (1, 2, 0)))
58+ patch = crop_chw (im , bbox , self .config .crop_sz )
6159
6260 target = patch - config .net_average_image
6361 self .net .update (torch .Tensor (np .expand_dims (target , axis = 0 )).cuda ())
@@ -68,12 +66,12 @@ def track(self, im):
6866 for i in range (self .config .num_scale ): # crop multi-scale search region
6967 window_sz = self .target_sz * (self .config .scale_factor [i ] * (1 + self .config .padding ))
7068 bbox = cxy_wh_2_bbox (self .target_pos , window_sz )
71- self .patch_crop [i , :] = resample (im , bbox , self .config .net_input_size , [ 0 , 0 , 0 ] )
69+ self .patch_crop [i , :] = crop_chw (im , bbox , self .config .crop_sz )
7270
7371 search = self .patch_crop - self .config .net_average_image
7472
7573 if self .gpu :
76- response = self .net (torch .Tensor (search ).cuda ()). cpu ()
74+ response = self .net (torch .Tensor (search ).cuda ())
7775 else :
7876 response = self .net (torch .Tensor (search ))
7977 peak , idx = torch .max (response .view (self .config .num_scale , - 1 ), 1 )
@@ -93,7 +91,7 @@ def track(self, im):
9391 # model update
9492 window_sz = self .target_sz * (1 + self .config .padding )
9593 bbox = cxy_wh_2_bbox (self .target_pos , window_sz )
96- patch = resample (im , bbox , self .config .net_input_size , [ 0 , 0 , 0 ] )
94+ patch = crop_chw (im , bbox , self .config .crop_sz )
9795 target = patch - self .config .net_average_image
9896 self .net .update (torch .Tensor (np .expand_dims (target , axis = 0 )).cuda (), lr = self .config .interp_factor )
9997
@@ -102,7 +100,7 @@ def track(self, im):
102100
103101if __name__ == '__main__' :
104102 # base dataset path and setting
105- dataset = 'OTB2015 '
103+ dataset = 'OTB2013 '
106104 base_path = join ('dataset' , dataset )
107105 json_path = join ('dataset' , dataset + '.json' )
108106 annos = json .load (open (json_path , 'r' ))
@@ -115,11 +113,10 @@ def track(self, im):
115113 config = TrackerConfig ()
116114 net = DCFNet (config )
117115 net .load_param (config .feature_path )
118- net .eval ( )
119- net .cuda ()
116+ # net.load_param('crop_125_2.0/checkpoint.pth.tar' )
117+ net .eval (). cuda ()
120118
121119 speed = []
122-
123120 # loop videos
124121 for video_id , video in enumerate (videos ): # run without resetting
125122 video_path_name = annos [video ]['name' ]
@@ -140,8 +137,7 @@ def track(self, im):
140137 # crop template
141138 window_sz = target_sz * (1 + config .padding )
142139 bbox = cxy_wh_2_bbox (target_pos , window_sz )
143- patch = resample (im , bbox , config .net_input_size , [0 , 0 , 0 ])
144- # cv2.imwrite('crop.jpg', np.transpose(patch[::-1,:,:], (1, 2, 0)))
140+ patch = crop_chw (im , bbox , config .crop_sz )
145141
146142 target = patch - config .net_average_image
147143 net .update (torch .Tensor (np .expand_dims (target , axis = 0 )).cuda ())
@@ -154,15 +150,12 @@ def track(self, im):
154150 for i in range (config .num_scale ): # crop multi-scale search region
155151 window_sz = target_sz * (config .scale_factor [i ] * (1 + config .padding ))
156152 bbox = cxy_wh_2_bbox (target_pos , window_sz )
157- patch_crop [i , :] = resample (im , bbox , config .net_input_size , [0 , 0 , 0 ])
158- # cv2.imwrite('crop2.jpg', np.transpose(patch_crop[0,::-1,:,:], (1, 2, 0)))
159- # cv2.imshow('crop.jpg', np.transpose(patch_crop[i], (1, 2, 0)).astype(np.float32) / 255)
160- # cv2.waitKey(0)
153+ patch_crop [i , :] = crop_chw (im , bbox , config .crop_sz )
161154
162155 search = patch_crop - config .net_average_image
163- response = net (torch .Tensor (search ).cuda ()). cpu ()
156+ response = net (torch .Tensor (search ).cuda ())
164157 peak , idx = torch .max (response .view (config .num_scale , - 1 ), 1 )
165- peak = peak .data .numpy () * config .scale_penalties
158+ peak = peak .data .cpu (). numpy () * config .scale_penalties
166159 best_scale = np .argmax (peak )
167160 r_max , c_max = np .unravel_index (idx [best_scale ], config .net_input_size )
168161
@@ -178,7 +171,7 @@ def track(self, im):
178171 # model update
179172 window_sz = target_sz * (1 + config .padding )
180173 bbox = cxy_wh_2_bbox (target_pos , window_sz )
181- patch = resample (im , bbox , config .net_input_size , [ 0 , 0 , 0 ] )
174+ patch = crop_chw (im , bbox , config .crop_sz )
182175 target = patch - config .net_average_image
183176 net .update (torch .Tensor (np .expand_dims (target , axis = 0 )).cuda (), lr = config .interp_factor )
184177
@@ -199,7 +192,7 @@ def track(self, im):
199192 print ('{:3d} Video: {:12s} Time: {:3.1f}s\t Speed: {:3.1f}fps' .format (video_id , video , toc , fps ))
200193
201194 # save result
202- test_path = './ result/OTB2015/ DCFNet_test/'
195+ test_path = join ( ' result' , dataset , ' DCFNet_test' )
203196 if not isdir (test_path ): makedirs (test_path )
204197 result_path = join (test_path , video + '.txt' )
205198 with open (result_path , 'w' ) as f :
@@ -208,4 +201,4 @@ def track(self, im):
208201
209202 print ('***Total Mean Speed: {:3.1f} (FPS)***' .format (np .mean (speed )))
210203
211- eval_auc ('OTB2015' , 'DCFNet_test' , 0 , 1 )
204+ eval_auc (dataset , 'DCFNet_test' , 0 , 1 )
0 commit comments