Esempio n. 1
0
 def test_gradcheck(self, device):
     B, C, H, W = 1, 1, 32, 32
     img = torch.rand(B, C, H, W, device=device)
     img = utils.tensor_to_gradcheck_var(img)  # to var
     local_feature = GFTTAffNetHardNet(2, True).to(device, img.dtype)
     assert gradcheck(local_feature,
                      img,
                      eps=1e-4,
                      atol=1e-4,
                      raise_exception=True)
Esempio n. 2
0
 def test_nomatch(self, device, dtype, data):
     matcher = LocalFeatureMatcher(GFTTAffNetHardNet(100),
                                   DescriptorMatcher('snn', 0.8)).to(
                                       device, dtype)
     data_dev = utils.dict_to(data, device, dtype)
     with torch.no_grad():
         out = matcher({
             "image0": data_dev["image0"],
             "image1": 0 * data_dev["image0"]
         })
     assert len(out['keypoints0']) == 0
Esempio n. 3
0
 def test_real_gftt(self, device, dtype, data):
     torch.random.manual_seed(0)
     # This is not unit test, but that is quite good integration test
     matcher = LocalFeatureMatcher(GFTTAffNetHardNet(2000),
                                   DescriptorMatcher('snn', 0.8)).to(
                                       device, dtype)
     ransac = RANSAC('homography', 1.0, 2048, 10).to(device, dtype)
     data_dev = utils.dict_to(data, device, dtype)
     pts_src = data_dev['pts0']
     pts_dst = data_dev['pts1']
     with torch.no_grad():
         out = matcher(data_dev)
     homography, inliers = ransac(out['keypoints0'], out['keypoints1'])
     assert inliers.sum().item() > 50  # we have enough inliers
     # Reprojection error of 5px is OK
     assert_close(transform_points(homography[None], pts_src[None]),
                  pts_dst[None],
                  rtol=5e-2,
                  atol=5)
Esempio n. 4
0
    def __init__(self,
                 initial_matcher: Optional[LocalFeature] = None,
                 fast_matcher: Optional[nn.Module] = None,
                 ransac: Optional[nn.Module] = None,
                 minimum_inliers_num: int = 30) -> None:
        super().__init__()
        self.initial_matcher = initial_matcher or (LocalFeatureMatcher(
            GFTTAffNetHardNet(3000), DescriptorMatcher('smnn', 0.95)))
        self.fast_matcher = fast_matcher or LoFTR('outdoor')
        self.ransac = ransac or RANSAC('homography',
                                       inl_th=5.0,
                                       batch_size=4096,
                                       max_iter=10,
                                       max_lo_iters=10)
        self.minimum_inliers_num = minimum_inliers_num

        # placeholders
        self.target: torch.Tensor
        self.target_initial_representation: Dict[str, torch.Tensor] = {}
        self.target_fast_representation: Dict[str, torch.Tensor] = {}
        self.previous_homography: Optional[torch.Tensor] = None

        self.reset_tracking()
Esempio n. 5
0
 def test_smoke(self, device, dtype):
     feat = GFTTAffNetHardNet().to(device, dtype)
     assert feat is not None