-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use average coordinate of merged keypoints during NMS #711
Open
johnwlambert
wants to merge
22
commits into
master
Choose a base branch
from
avg-coord-nms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0e2b0c4
add pure-retrieval baseline
96bcc53
add nms option
1212d65
int32 to MatchIndicesMap instead of uint32
a3c023d
make BA return correct shape
e5aa0fa
Merge branch 'master' of https://github.com/borglab/gtsfm into add-pu…
83775bb
fix bug in script flag elif cond
9c4f853
merge conflict
edbddbe
Merge branch 'master' of https://github.com/borglab/gtsfm into add-pu…
aab676f
fix test
3bf9c30
update var name
7b0066d
update var name
dd5c99c
fix format
b930e76
Merge branch 'master' of https://github.com/borglab/gtsfm into add-pu…
e96326e
Merge branch 'master' of https://github.com/borglab/gtsfm into add-pu…
69dc6c6
use running mean keypoint loc
07918c8
improve comment
ffaf257
fix index error
c2e7909
fix merge conflict
d8a04fc
Merge branch 'master' of https://github.com/borglab/gtsfm into avg-co…
cd41a97
Merge branch 'master' of https://github.com/borglab/gtsfm into avg-co…
7896bf1
Merge branch 'master' of https://github.com/borglab/gtsfm into avg-co…
ccdf831
remove superfluous print statement
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,17 @@ | |
|
||
|
||
class KeypointAggregatorDedup(KeypointAggregatorBase): | ||
"""Keypoint aggregator with de-duplication.""" | ||
"""Keypoint aggregator with de-duplication of keypoints within each image.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize global variables""" | ||
def __init__(self, nms_merge_radius: float = 3) -> None: | ||
"""Initialize global variables. | ||
|
||
Args: | ||
nms_merge_radius: Radius (in pixels) to use when merging detections within the same view (image). | ||
Note that tracks are merged, not suppressed. | ||
""" | ||
self.duplicates_found = 0 | ||
self.nms_merge_radius = nms_merge_radius | ||
|
||
def append_unique_keypoints( | ||
self, i: int, keypoints: Keypoints, per_image_kpt_coordinates: Dict[Tuple[int, int], np.ndarray] | ||
|
@@ -45,11 +51,16 @@ def append_unique_keypoints( | |
|
||
for k, uv in enumerate(keypoints.coordinates): | ||
diff_norms = np.linalg.norm(per_image_kpt_coordinates[i] - uv, axis=1) | ||
# TODO(johnwlambert,ayushbaid): test loosening threshold below to some epsilon. | ||
is_identical = np.any(diff_norms == 0) | ||
if len(per_image_kpt_coordinates[i]) > 0 and is_identical: | ||
is_duplicate = np.any(diff_norms <= self.nms_merge_radius) | ||
if len(per_image_kpt_coordinates[i]) > 0 and is_duplicate: | ||
self.duplicates_found += 1 | ||
i_indices[k] = np.argmin(diff_norms) | ||
img_global_kpt_idx = np.argmin(diff_norms) | ||
i_indices[k] = img_global_kpt_idx | ||
# Modify global keypoint coordinate to be set to average value of merged detections, instead of | ||
# using the first identified coordinate. | ||
updated_uv = np.mean([per_image_kpt_coordinates[i][img_global_kpt_idx], uv], axis=0) | ||
per_image_kpt_coordinates[i][img_global_kpt_idx] = updated_uv | ||
Comment on lines
+59
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you take the mean after you've determined which keypoints are to be merged? |
||
|
||
else: | ||
i_indices[k] = i_count | ||
i_count += 1 | ||
|
@@ -99,10 +110,11 @@ def aggregate( | |
per_image_kpt_coordinates, i2_indices = self.append_unique_keypoints( | ||
i=i2, keypoints=keypoints_i2, per_image_kpt_coordinates=per_image_kpt_coordinates | ||
) | ||
putative_corr_idxs = np.stack([i1_indices, i2_indices], axis=-1).astype(np.uint16) | ||
putative_corr_idxs = np.stack([i1_indices, i2_indices], axis=-1).astype(np.int32) | ||
putative_corr_idxs_dict[(i1, i2)] = putative_corr_idxs | ||
|
||
logger.info(f"Merged {self.duplicates_found} duplicates during de-duplication.") | ||
print(f"Merged {self.duplicates_found} duplicates during de-duplication.") | ||
# Reset global state. | ||
self.duplicates_found = 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tested with len(per_image_kpt_coordinates[i]) == 0? does the
<=
work with empty arrrays?Also np.any should be false in that case, so you would not need that condition at all?