class SiamRPNPP(): def __init__(self,dataset=''): if 'OTB' in dataset: cfg_file = os.path.join(project_path_,'pysot/experiments/siamrpn_r50_l234_dwxcorr_otb/config.yaml') snapshot = os.path.join(project_path_,'pysot/experiments/siamrpn_r50_l234_dwxcorr_otb/model.pth') elif 'LT' in dataset: cfg_file = os.path.join(project_path_, 'pysot/experiments/siamrpn_r50_l234_dwxcorr_lt/config.yaml') snapshot = os.path.join(project_path_, 'pysot/experiments/siamrpn_r50_l234_dwxcorr_lt/model.pth') else: cfg_file = os.path.join(project_path_, 'pysot/experiments/siamrpn_r50_l234_dwxcorr/config.yaml') snapshot = os.path.join(project_path_, 'pysot/experiments/siamrpn_r50_l234_dwxcorr/model.pth') # load config cfg.merge_from_file(cfg_file) # create model self.model = ModelBuilder()# A Neural Network.(a torch.nn.Module) # load model self.model = load_pretrain(self.model, snapshot).cuda().eval() def get_heat_map(self, X_crop, softmax=False): score_map = self.model.track(X_crop)['cls']#(N,2x5,25,25) score_map = score_map.permute(1, 2, 3, 0).contiguous().view(2, -1).permute(1, 0)#(5HWN,2) if softmax: score_map = F.softmax(score_map, dim=1).data[:, 1]#(5HWN,) return score_map def get_cls_reg(self, X_crop, softmax=False): outputs = self.model.track(X_crop)#(N,2x5,25,25) score_map = outputs['cls'].permute(1, 2, 3, 0).contiguous().view(2, -1).permute(1, 0)#(5HWN,2) reg_res = outputs['loc'].permute(1, 2, 3, 0).contiguous().view(4, -1) if softmax: score_map = F.softmax(score_map, dim=1).data[:, 1]#(5HWN,) return score_map, reg_res
if args.mask: extractor.pick = ('conv1', 'res2', 'res3', 'res4') else: extractor.pick = ('res3', 'res4', 'res5') c_out = extractor(z) for i in range(len(c_out)): np.testing.assert_almost_equal(c_out[i].data, outs[i], decimal=5) model.template(torch.FloatTensor(z)) chainer_model.template(z) np.testing.assert_almost_equal(model.zf.detach().numpy(), chainer_model.zs.data, decimal=5) t_out = model.track(torch.FloatTensor(x)) c_out = chainer_model.track(x) t_conf = t_out['cls'].detach().numpy() t_loc = t_out['loc'].detach().numpy() np.testing.assert_almost_equal(t_conf, c_out[0].data, decimal=5) np.testing.assert_almost_equal(t_loc, c_out[1].data, decimal=5) if args.mask: t_mask = t_out['mask'].detach().numpy() np.testing.assert_almost_equal(t_mask, c_out[2].data, decimal=5) pos = (12, 11) t_out = model.mask_refine(pos).detach().numpy() c_out = chainer_model.refine_mask(pos).data np.testing.assert_almost_equal(t_out, c_out, decimal=5) print('test done')