Realcat commited on
Commit
de8bee7
1 Parent(s): 5e02733

update: api

Browse files
Files changed (3) hide show
  1. common/api.py +9 -25
  2. common/config.yaml +23 -23
  3. test_app_cli.py +38 -31
common/api.py CHANGED
@@ -27,28 +27,6 @@ warnings.simplefilter("ignore")
27
 
28
  class ImageMatchingAPI(torch.nn.Module):
29
  default_conf = {
30
- "dense": True,
31
- "matcher": {
32
- "model": {
33
- "name": "topicfm",
34
- "match_threshold": 0.2,
35
- }
36
- },
37
- "feature": {
38
- "model": {
39
- "name": "xfeat",
40
- "max_keypoints": 1024,
41
- "keypoint_threshold": 0.015,
42
- },
43
- "preprocessing": {
44
- "grayscale": False,
45
- "resize_max": 1600,
46
- "force_resize": True,
47
- "width": 640,
48
- "height": 480,
49
- "dfactor": 8,
50
- },
51
- },
52
  "ransac": {
53
  "enable": True,
54
  "estimator": "poselib",
@@ -83,7 +61,7 @@ class ImageMatchingAPI(torch.nn.Module):
83
  """
84
  super().__init__()
85
  self.device = device
86
- self.conf = self.parse_match_config(conf)
87
  self._updata_config(detect_threshold, max_keypoints, match_threshold)
88
  self._init_models()
89
  if device == "cuda":
@@ -126,14 +104,20 @@ class ImageMatchingAPI(torch.nn.Module):
126
  ):
127
  self.dense = self.conf["dense"]
128
  if self.conf["dense"]:
129
- self.conf["matcher"]["model"]["match_threshold"] = match_threshold
 
 
 
 
 
130
  else:
131
  self.conf["feature"]["model"]["max_keypoints"] = max_keypoints
132
  self.conf["feature"]["model"][
133
  "keypoint_threshold"
134
  ] = detect_threshold
 
 
135
  self.match_conf = self.conf["matcher"]
136
- self.extract_conf = self.conf["feature"]
137
 
138
  def _init_models(self):
139
  # initialize matcher
 
27
 
28
  class ImageMatchingAPI(torch.nn.Module):
29
  default_conf = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  "ransac": {
31
  "enable": True,
32
  "estimator": "poselib",
 
61
  """
62
  super().__init__()
63
  self.device = device
64
+ self.conf = {**self.default_conf, **conf}
65
  self._updata_config(detect_threshold, max_keypoints, match_threshold)
66
  self._init_models()
67
  if device == "cuda":
 
104
  ):
105
  self.dense = self.conf["dense"]
106
  if self.conf["dense"]:
107
+ try:
108
+ self.conf["matcher"]["model"][
109
+ "match_threshold"
110
+ ] = match_threshold
111
+ except TypeError as e:
112
+ breakpoint()
113
  else:
114
  self.conf["feature"]["model"]["max_keypoints"] = max_keypoints
115
  self.conf["feature"]["model"][
116
  "keypoint_threshold"
117
  ] = detect_threshold
118
+ self.extract_conf = self.conf["feature"]
119
+
120
  self.match_conf = self.conf["matcher"]
 
121
 
122
  def _init_models(self):
123
  # initialize matcher
common/config.yaml CHANGED
@@ -16,29 +16,29 @@ defaults:
16
  setting_geometry: Homography
17
 
18
  matcher_zoo:
19
- omniglue:
20
- enable: true
21
- matcher: omniglue
22
- dense: true
23
- info:
24
- name: OmniGlue
25
- source: "CVPR 2024"
26
- github: https://github.com/Vincentqyw/omniglue-onnx
27
- paper: https://arxiv.org/abs/2405.12979
28
- project: https://hwjiang1510.github.io/OmniGlue/
29
- display: true
30
- DUSt3R:
31
- # TODO: duster is under development
32
- enable: false
33
- matcher: duster
34
- dense: true
35
- info:
36
- name: DUSt3R #dispaly name
37
- source: "CVPR 2024"
38
- github: https://github.com/naver/dust3r
39
- paper: https://arxiv.org/abs/2312.14132
40
- project: https://dust3r.europe.naverlabs.com
41
- display: true
42
  GIM(dkm):
43
  matcher: gim(dkm)
44
  dense: true
 
16
  setting_geometry: Homography
17
 
18
  matcher_zoo:
19
+ # omniglue:
20
+ # enable: true
21
+ # matcher: omniglue
22
+ # dense: true
23
+ # info:
24
+ # name: OmniGlue
25
+ # source: "CVPR 2024"
26
+ # github: https://github.com/Vincentqyw/omniglue-onnx
27
+ # paper: https://arxiv.org/abs/2405.12979
28
+ # project: https://hwjiang1510.github.io/OmniGlue/
29
+ # display: true
30
+ # DUSt3R:
31
+ # # TODO: duster is under development
32
+ # enable: false
33
+ # matcher: duster
34
+ # dense: true
35
+ # info:
36
+ # name: DUSt3R #dispaly name
37
+ # source: "CVPR 2024"
38
+ # github: https://github.com/naver/dust3r
39
+ # paper: https://arxiv.org/abs/2312.14132
40
+ # project: https://dust3r.europe.naverlabs.com
41
+ # display: true
42
  GIM(dkm):
43
  matcher: gim(dkm)
44
  dense: true
test_app_cli.py CHANGED
@@ -41,29 +41,32 @@ def test_one():
41
  image1 = cv2.imread(str(img_path2))[:, :, ::-1] # RGB
42
  # sparse
43
  conf = {
44
- "dense": False,
45
- "matcher": {
46
- "model": {
47
- "name": "NN-mutual",
48
- "match_threshold": 0.2,
49
- }
50
- },
51
  "feature": {
 
52
  "model": {
53
- "name": "xfeat",
54
- "max_keypoints": 1024,
55
- "keypoint_threshold": 0.015,
56
- }
 
 
 
 
 
 
 
 
 
57
  },
58
- "ransac": {
59
- "enable": True,
60
- "estimator": "poselib",
61
- "geometry": "homography",
62
- "method": "RANSAC",
63
- "reproj_threshold": 3,
64
- "confidence": 0.9999,
65
- "max_iter": 10000,
66
  },
 
67
  }
68
  api = ImageMatchingAPI(conf=conf, device=device)
69
  api(image0, image1)
@@ -73,24 +76,28 @@ def test_one():
73
 
74
  # dense
75
  conf = {
76
- "dense": True,
77
  "matcher": {
 
78
  "model": {
79
  "name": "loftr",
 
 
80
  "match_threshold": 0.2,
81
- }
82
- },
83
- "feature": {},
84
- "ransac": {
85
- "enable": True,
86
- "estimator": "poselib",
87
- "geometry": "homography",
88
- "method": "RANSAC",
89
- "reproj_threshold": 3,
90
- "confidence": 0.9999,
91
- "max_iter": 10000,
92
  },
 
93
  }
 
94
  api = ImageMatchingAPI(conf=conf, device=device)
95
  api(image0, image1)
96
  log_path = ROOT / "experiments" / "one"
 
41
  image1 = cv2.imread(str(img_path2))[:, :, ::-1] # RGB
42
  # sparse
43
  conf = {
 
 
 
 
 
 
 
44
  "feature": {
45
+ "output": "feats-superpoint-n4096-rmax1600",
46
  "model": {
47
+ "name": "superpoint",
48
+ "nms_radius": 3,
49
+ "max_keypoints": 4096,
50
+ "keypoint_threshold": 0.005,
51
+ },
52
+ "preprocessing": {
53
+ "grayscale": True,
54
+ "force_resize": True,
55
+ "resize_max": 1600,
56
+ "width": 640,
57
+ "height": 480,
58
+ "dfactor": 8,
59
+ },
60
  },
61
+ "matcher": {
62
+ "output": "matches-NN-mutual",
63
+ "model": {
64
+ "name": "nearest_neighbor",
65
+ "do_mutual_check": True,
66
+ "match_threshold": 0.2,
67
+ },
 
68
  },
69
+ "dense": False,
70
  }
71
  api = ImageMatchingAPI(conf=conf, device=device)
72
  api(image0, image1)
 
76
 
77
  # dense
78
  conf = {
 
79
  "matcher": {
80
+ "output": "matches-loftr",
81
  "model": {
82
  "name": "loftr",
83
+ "weights": "outdoor",
84
+ "max_keypoints": 2000,
85
  "match_threshold": 0.2,
86
+ },
87
+ "preprocessing": {
88
+ "grayscale": True,
89
+ "resize_max": 1024,
90
+ "dfactor": 8,
91
+ "width": 640,
92
+ "height": 480,
93
+ "force_resize": True,
94
+ },
95
+ "max_error": 1,
96
+ "cell_size": 1,
97
  },
98
+ "dense": True,
99
  }
100
+
101
  api = ImageMatchingAPI(conf=conf, device=device)
102
  api(image0, image1)
103
  log_path = ROOT / "experiments" / "one"