def test_transform_siamfc(self):
        base_dataset = VOT(self.vot_dir, return_rect=True, download=True)
        transform = TransformSiamFC(stats_path=self.stats_path)
        dataset = Pairwise(base_dataset, transform=transform, subset='train')
        self.assertGreater(len(dataset), 0)

        for crop_z, crop_x, labels, weights in dataset:
            self.assertAlmostEqual(weights[labels == 1].sum().item(),
                                   weights[labels == 0].sum().item())
            self.assertAlmostEqual(weights.sum().item(),
                                   labels[labels >= 0].numel())
            self.assertEqual(
                weights[labels == transform.ignore_label].sum().item(), 0)

        if self.visualize:
            crop_z, crop_x, labels, weights = random.choice(dataset)
            crop_z = F.to_pil_image(crop_z / 255.0)
            crop_x = F.to_pil_image(crop_x / 255.0)
            labels = self._rescale(labels.cpu().squeeze().numpy())
            weights = self._rescale(weights.cpu().squeeze().numpy())

            bndbox_z = np.array([31, 31, 64, 64])
            bndbox_x = np.array([95, 95, 64, 64])

            show_frame(crop_z, bndbox_z, fig_n=1, pause=1)
            show_frame(crop_x, bndbox_x, fig_n=2, pause=1)
            show_frame(labels, fig_n=3, pause=1, cmap='hot')
            show_frame(weights, fig_n=4, pause=5, cmap='hot')
Пример #2
0
    def test_transform_goturn(self):
        base_dataset = VOT(self.vot_dir, return_rect=True, download=True)
        transform = TransformGOTURN()
        dataset = Pairwise(base_dataset,
                           transform,
                           pairs_per_video=1,
                           frame_range=1,
                           causal=True)
        self.assertGreater(len(dataset), 0)

        for crop_z, crop_x, labels in dataset:
            self.assertEqual(crop_z.size(), crop_x.size())

        if self.visualize:
            for t in range(10):
                crop_z, crop_x, labels = random.choice(dataset)
                mean_color = torch.tensor(transform.mean_color).float().view(
                    3, 1, 1)
                crop_z = F.to_pil_image((crop_z + mean_color) / 255.0)
                crop_x = F.to_pil_image((crop_x + mean_color) / 255.0)
                labels = labels.cpu().numpy()
                labels *= transform.out_size / transform.label_scale_factor

                bndbox = np.concatenate([labels[:2], labels[2:] - labels[:2]])
                show_frame(crop_x, bndbox, fig_n=1, pause=1)
Пример #3
0
    def test_goturn_track(self):
        dataset = VOT(self.vot_dir, return_rect=True, download=True)
        tracker = TrackerGOTURN(self.net_path)

        img_files, anno = random.choice(dataset)
        rects, speed = tracker.track(img_files, anno[0, :],
                                     visualize=True)
        self.assertEqual(rects.shape, anno.shape)
Пример #4
0
    def test_siamfc_track_v2(self):
        dataset = VOT(self.vot_dir, return_rect=True, download=True)
        tracker = TrackerSiamFC(
            branch='alexv2', net_path=self.net_v2, z_lr=0.01,
            response_up=8, scale_step=1.0816, window_influence=0.25)

        img_files, anno = random.choice(dataset)
        rects, speed = tracker.track(img_files, anno[0, :],
                                     visualize=True)
        self.assertEqual(rects.shape, anno.shape)
Пример #5
0
    def test_load(self):
        dataset = VOT(self.vot_dir, return_rect=True)
        self.assertGreater(len(dataset), 0)

        for img_files, anno in dataset:
            self.assertGreater(len(img_files), 0)
            self.assertEqual(len(img_files), len(anno))

        if self.visualize:
            img_files, anno = random.choice(dataset)
            for f, img_file in enumerate(img_files):
                image = Image.open(img_file)
                show_frame(image, anno[f, :])
Пример #6
0
    def test_goturn_train(self):
        tracker = TrackerGOTURN(net_path=self.net_path)
        transform = TransformGOTURN()

        base_dataset = VOT(self.vot_dir, return_rect=True, download=True)
        dataset = Pairwise(
            base_dataset, transform, frame_range=1, causal=True)
        dataloader = DataLoader(dataset, batch_size=2, shuffle=True)

        # training loop
        for it, batch in enumerate(dataloader):
            update_lr = it == 0
            loss = tracker.step(batch, backward=True, update_lr=update_lr)
            print('Iter: {} Loss: {:.6f}'.format(it + 1, loss))

        # validation loop
        for it, batch in enumerate(dataloader):
            loss = tracker.step(batch, backward=False)
            print('Val. Iter: {} Loss: {:.6f}'.format(it + 1, loss))
Пример #7
0
    def test_siamfc_train_v2(self):
        tracker = TrackerSiamFC(branch='alexv2')
        transform = TransformSiamFC(
            stats_path=self.stats_path, score_sz=33,
            r_pos=8, total_stride=4)

        base_dataset = VOT(self.vot_dir, return_rect=True, download=True)
        dataset = Pairwise(base_dataset, transform, pairs_per_video=1)
        dataloader = DataLoader(dataset, batch_size=2, shuffle=True)

        # training loop
        for it, batch in enumerate(dataloader):
            update_lr = it == 0
            loss = tracker.step(batch, backward=True, update_lr=update_lr)
            print('Iter: {} Loss: {:.6f}'.format(it + 1, loss))

        # val loop
        for it, batch in enumerate(dataloader):
            loss = tracker.step(batch, backward=False)
            print('Val. Iter: {} Loss: {:.6f}'.format(it + 1, loss))
Пример #8
0
 def test_download(self):
     dataset = VOT(self.vot_dir, download=True, version=2017)
     self.assertGreater(len(dataset), 0)
 def test_experiment_unsupervised(self):
     experiment = ExperimentUnsupervised(log_dir='results/SiamFC')
     tracker = TrackerSiamFC(net_path=self.net_path)
     dataset = VOT(self.vot_dir, return_rect=True)
     experiment.run(tracker, dataset, visualize=True)