Skip to content

Commit 6d9cbc2

Browse files
committed
Have separate model configs for CPU and GPU
Ideally model parameters would be adjusted dynamically based on detected matching speed at runtime regardless of CPU/GPU
1 parent c4275c2 commit 6d9cbc2

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

ros/gisnav/gisnav/core/pose_node.py

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ class PoseNode(Node):
5858
finding matching keypoints and solving the PnP problem.
5959
"""
6060

61-
CONFIDENCE_THRESHOLD = 0.3
61+
CONFIDENCE_THRESHOLD = 0.5
6262
"""Confidence threshold for filtering out bad keypoint matches"""
6363

64-
MIN_MATCHES = 30
64+
MIN_MATCHES = 15
6565
"""Minimum number of keypoint matches before attempting pose estimation"""
6666

6767
MAX_KEYPOINTS = 1024
@@ -83,29 +83,43 @@ def __init__(self, *args, **kwargs):
8383

8484
self._cv_bridge = CvBridge()
8585

86-
# Initialize DL model for map matching
87-
self._matcher = (
88-
LightGlueMatcher(
89-
"sift",
90-
params={
91-
"n_layers": 6,
92-
"filter_threshold": self.CONFIDENCE_THRESHOLD,
93-
"depth_confidence": 0.8,
94-
"width_confidence": -1,
95-
},
96-
)
97-
.to(self._device)
98-
.eval()
99-
)
100-
86+
# TODO: adjust dynamically based on runtime matching speed, not statically
87+
# depending on whether we are running on cpu or gpu (even though it is a good
88+
# proxy for slow vs fast matching).
10189
if self._device == "cpu":
10290
self.get_logger().warning(
10391
"Using CPU instead of GPU for matching - limiting"
104-
"max number of keypoints to improve matching speed. "
105-
"Performance may be negatively affected."
92+
"max number of keypoints and enabling adaptive mechanisms to improve "
93+
"matching speed. Accuracy may be negatively affected."
94+
)
95+
self._matcher = (
96+
LightGlueMatcher(
97+
"sift",
98+
params={
99+
"n_layers": 5,
100+
"filter_threshold": self.CONFIDENCE_THRESHOLD,
101+
"depth_confidence": 0.99,
102+
"width_confidence": 0.99,
103+
},
104+
)
105+
.to(self._device)
106+
.eval()
106107
)
107108
self._extractor = cv2.SIFT_create(self.MAX_KEYPOINTS)
108109
else:
110+
self._matcher = (
111+
LightGlueMatcher(
112+
"sift",
113+
params={
114+
"n_layers": 9,
115+
"filter_threshold": self.CONFIDENCE_THRESHOLD,
116+
"depth_confidence": -1,
117+
"width_confidence": -1,
118+
},
119+
)
120+
.to(self._device)
121+
.eval()
122+
)
109123
self._extractor = cv2.SIFT_create()
110124

111125
self._cached_stamp_kps_desc: Optional[

ros/gisnav/gisnav/core/twist_node.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def __init__(self, *args, **kwargs):
8282
# Initialize ORB detector and brute force matcher for VO
8383
# (smooth relative position with drift)
8484
if self._device == "cpu":
85+
# TODO: PoseNode limits max number of keypoints - do we need to do same here
86+
# like we are now doing?
8587
self.get_logger().warning(
8688
"Using CPU instead of GPU for matching - limiting"
8789
"max number of keypoints to improve matching speed. "
@@ -167,6 +169,10 @@ def _publish_keypoints(
167169
:return: Point cloud message representing the keypoints and descriptors
168170
"""
169171
# Create a structured array for our custom point type
172+
if not isinstance(kps, np.ndarray):
173+
# TODO use narrow types decorator here
174+
self.get_logger().error(f"Provided keypoints was not a numpy array: {kps}")
175+
return None
170176
data = np.empty(kps.shape[0], dtype=KEYPOINT_DTYPE)
171177
data["x"] = kps[:, 0]
172178
data["y"] = kps[:, 1]

0 commit comments

Comments
 (0)