Esempio n. 1
0
 def init_target_boxes(self):
     """Get the target bounding boxes for the initial augmented samples."""
     self.classifier_target_box = self.get_iounet_box(
         self.pos, self.target_sz, self.init_sample_pos,
         self.init_sample_scale)
     init_target_boxes = TensorList()
     for T in self.transforms:
         init_target_boxes.append(
             self.classifier_target_box +
             torch.Tensor([T.shift[1], T.shift[0], 0, 0]))
     init_target_boxes = torch.cat(init_target_boxes.view(1, 4),
                                   0).to(self.p.device)
     self.target_boxes = init_target_boxes.new_zeros(
         self.p.sample_memory_size, 4)
     self.target_boxes[:init_target_boxes.shape[0], :] = init_target_boxes
     return init_target_boxes
Esempio n. 2
0
    def init_iou_net(self, backbone_feat):
        # Setup IoU net and objective
        for p in self.net.bb_regressor.parameters():
            p.requires_grad = False

        # Get target boxes for the different augmentations
        self.classifier_target_box = self.get_iounet_box(
            self.pos, self.target_sz, self.init_sample_pos,
            self.init_sample_scale)
        target_boxes = TensorList()
        if self.p.iounet_augmentation:
            for T in self.transforms:
                if not isinstance(
                        T, (augmentation.Identity, augmentation.Translation,
                            augmentation.FlipHorizontal,
                            augmentation.FlipVertical, augmentation.Blur)):
                    break
                target_boxes.append(
                    self.classifier_target_box +
                    torch.Tensor([T.shift[1], T.shift[0], 0, 0]))
        else:
            target_boxes.append(self.classifier_target_box + torch.Tensor([
                self.transforms[0].shift[1], self.transforms[0].shift[0], 0, 0
            ]))
        target_boxes = torch.cat(target_boxes.view(1, 4), 0).to(self.p.device)

        # Get iou features
        iou_backbone_feat = self.get_iou_backbone_features(backbone_feat)

        # Remove other augmentations such as rotation
        iou_backbone_feat = TensorList(
            [x[:target_boxes.shape[0], ...] for x in iou_backbone_feat])

        # Get modulation vector
        self.iou_modulation = self.get_iou_modulation(iou_backbone_feat,
                                                      target_boxes)
        self.iou_modulation = TensorList(
            [x.detach().mean(0) for x in self.iou_modulation])