def main(): global args, v_id args = parser.parse_args() net = SiamRPNotb() net.load_state_dict(torch.load(join(realpath(dirname(__file__)), 'SiamRPNOTB.model'))) net.eval().cuda() dataset = load_dataset(args.dataset) fps_list = [] for v_id, video in enumerate(dataset.keys()): fps_list.append(track_video(net, dataset[video])) print('Mean Running Speed {:.1f}fps'.format(np.mean(np.array(fps_list))))
def SiamRPN_load(image, boxes, txt_path): if not os.path.exists(txt_path): os.makedirs(txt_path) multiTracker = cv2.MultiTracker_create() net = SiamRPNotb() net.load_state_dict( torch.load(join(realpath(dirname(__file__)), 'SiamRPNOTB.model'))) net.eval().cuda() states, labels = [], [] for bbox in boxes: #init_rbox = [bbox[0],bbox[1],bbox[0]+bbox[2],bbox[1],bbox[0]+bbox[2],bbox[1]+bbox[3],bbox[0],bbox[1]+bbox[3]] init_rbox = [ bbox[0], bbox[1], bbox[2], bbox[1], bbox[2], bbox[3], bbox[0], bbox[3] ] [cx, cy, w, h] = get_axis_aligned_bbox(init_rbox) # print(cx, cy, w, h,'-----',init_rbox) target_pos, target_sz = np.array([cx, cy]), np.array([w, h]) states.append(SiamRPN_init(image, target_pos, target_sz, net)) labels.append(bbox[-1]) return states, labels
class DaSiamRPN(BaseTracker): def __init__(self): super(DaSiamRPN, self).__init__(name="DaSiamRPN") self.net_file = path_config.DASIAMRPN_MODEL def initialize(self, image_file, box): self.net = SiamRPNotb() self.net.load_state_dict(torch.load(self.net_file)) self.net.eval().cuda() image = cv2.imread(image_file) box = box - np.array([1, 1, 0, 0]) self.state = SiamRPN_init(image, box[:2] + box[2:] / 2.0, box[2:], self.net) # init tracker def track(self, image_file): image = cv2.imread(image_file) self.state = SiamRPN_track(self.state, image) # track center = self.state["target_pos"] + 1 target_sz = self.state["target_sz"] box = cxy_wh_2_rect(center, target_sz) return box