Пример #1
0
    def __init__(self, params, model_path=None, **kargs):
        super(TrackerSiamRPNBIG, self).__init__(name='SiamRPN',
                                                is_deterministic=True)

        self.model = SiameseAlexNet()

        self.cuda = torch.cuda.is_available()
        self.device = torch.device('cuda:0' if self.cuda else 'cpu')

        checkpoint = torch.load(model_path, map_location=self.device)
        #print("1")
        if 'model' in checkpoint.keys():
            self.model.load_state_dict(
                torch.load(model_path, map_location=self.device)['model'])
        else:
            self.model.load_state_dict(
                torch.load(model_path, map_location=self.device))

        if self.cuda:
            self.model = self.model.cuda()
        self.model.eval()
        self.transforms = transforms.Compose([ToTensor()])

        valid_scope = 2 * config.valid_scope + 1
        self.anchors = util.generate_anchors(config.total_stride,
                                             config.anchor_base_size,
                                             config.anchor_scales,
                                             config.anchor_ratios, valid_scope)
        self.window = np.tile(
            np.outer(np.hanning(config.score_size),
                     np.hanning(config.score_size))[None, :],
            [config.anchor_num, 1, 1]).flatten()

        self.data_loader = TrackerDataLoader()
Пример #2
0
    def __init__(self, net_path=None, **kargs):
        super(TrackerSiamRPN, self).__init__(name='SiamRPN',
                                             is_deterministic=True)
        '''setup GPU device if available'''
        self.cuda = torch.cuda.is_available()
        self.device = torch.device('cuda:0' if self.cuda else 'cpu')
        '''setup model'''
        self.net = SiameseAlexNet()

        if net_path is not None:
            self.net.load_state_dict(
                torch.load(net_path,
                           map_location=lambda storage, loc: storage))
        if self.cuda:
            self.net = self.net.to(self.device)
        '''setup optimizer'''
        self.optimizer = torch.optim.SGD(self.net.parameters(),
                                         lr=config.lr,
                                         momentum=config.momentum,
                                         weight_decay=config.weight_decay)

        self.anchors = util.generate_anchors(config.anchor_total_stride,
                                             config.anchor_base_size,
                                             config.anchor_scales,
                                             config.anchor_ratios,
                                             config.anchor_valid_scope)
Пример #3
0
    def __init__(self, net_path=None, **kargs):
        super(TrackerSiamRPN, self).__init__(name='SiamRPN',
                                             is_deterministic=True)
        '''setup GPU device if available'''
        self.cuda = torch.cuda.is_available()
        self.device = torch.device('cuda' if self.cuda else 'cpu')
        '''setup model'''
        self.net = SiameseAlexNet()
        self.net.init_weights()

        if net_path is not None:
            self.net.load_state_dict(
                torch.load(net_path,
                           map_location=lambda storage, loc: storage))
        if self.cuda:
            print('Training with GPU.')
            self.net = self.net.to(self.device)
        '''setup optimizer'''
        print("Learning rate: {}".format(config.lr))
        self.optimizer = torch.optim.SGD(self.net.parameters(),
                                         lr=config.lr,
                                         momentum=config.momentum,
                                         weight_decay=config.weight_decay)