vismatch.im_models.silk
Standalone SiLK (Self-supervised Interest point Learning with Keypoints) implementation. Reference: https://github.com/facebookresearch/silk Paper: https://arxiv.org/abs/2304.06194
Functions
|
Extract keypoints from detector logits. |
|
Load SiLK model from safetensors. |
|
Match descriptors using mutual nearest neighbors with optional ratio test. |
|
Sample descriptors at keypoint locations. |
|
Non-maximum suppression on a 2D score map. |
Classes
|
Descriptor head: outputs dense descriptors. |
|
Detector head: outputs logits for keypoint detection. |
|
Self-supervised Interest point Learning with Keypoints (SiLK). |
|
SiLK matcher using standalone implementation. |
VGG-style backbone for SiLK. |
|
|
A single VGG-style conv block: Conv -> ReLU -> BatchNorm. |
- vismatch.im_models.silk.simple_nms(scores, radius=4)[source][source]
Non-maximum suppression on a 2D score map.
- vismatch.im_models.silk.extract_keypoints(logits, detection_threshold=0.0, nms_radius=4, top_k=10000, border_dist=4)[source][source]
Extract keypoints from detector logits.
- Parameters:
logits (torch.Tensor) – (B, 1, H, W) detector output
detection_threshold (float, optional) – minimum score threshold. Defaults to 0.0.
nms_radius (int, optional) – radius for non-maximum suppression. Defaults to 4.
top_k (int, optional) – maximum number of keypoints to return. Defaults to 10000.
border_dist (int, optional) – distance from border to exclude keypoints. Defaults to 4.
- Returns:
list of (N, 3) tensors with (row, col, score) for each batch item
- Return type:
list[torch.Tensor]
- vismatch.im_models.silk.sample_descriptors(descriptors, keypoints, mode='bilinear')[source][source]
Sample descriptors at keypoint locations.
- Parameters:
descriptors (torch.Tensor) – (B, C, H, W) descriptor map
keypoints (list[torch.Tensor]) – list of (N, 3) tensors with (row, col, score)
mode (str, optional) – interpolation mode. Defaults to “bilinear”.
- Returns:
list of (N, C) descriptor tensors
- Return type:
list[torch.Tensor]
- vismatch.im_models.silk.match_descriptors_mnn(desc0, desc1, threshold=0.8, mode='ratio-test')[source][source]
Match descriptors using mutual nearest neighbors with optional ratio test.
- Parameters:
desc0 (torch.Tensor) – (N, C) descriptors from image 0
desc1 (torch.Tensor) – (M, C) descriptors from image 1
threshold (float, optional) – ratio threshold (for ratio-test) or distance threshold. Defaults to 0.8.
mode (str, optional) – “ratio-test”, “mnn”, or “double-softmax”. Defaults to “ratio-test”.
- Returns:
(K, 2) tensor of match indices
- Return type:
torch.Tensor
- class vismatch.im_models.silk.VGGBlock(in_channels, out_channels, kernel_size=3)[source][source]
Bases:
ModuleA single VGG-style conv block: Conv -> ReLU -> BatchNorm.
- forward(x)[source][source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class vismatch.im_models.silk.VGGBackbone[source][source]
Bases:
ModuleVGG-style backbone for SiLK.
- forward(x)[source][source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class vismatch.im_models.silk.DetectorHead(in_channels=128)[source][source]
Bases:
ModuleDetector head: outputs logits for keypoint detection.
- forward(x)[source][source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class vismatch.im_models.silk.DescriptorHead(in_channels=128, out_channels=128)[source][source]
Bases:
ModuleDescriptor head: outputs dense descriptors.
- forward(x)[source][source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class vismatch.im_models.silk.SiLKModel(descriptor_dim=128)[source][source]
Bases:
ModuleSelf-supervised Interest point Learning with Keypoints (SiLK).
- vismatch.im_models.silk.load_silk_model(weights_path, device='cpu')[source][source]
Load SiLK model from safetensors.
- class vismatch.im_models.silk.SilkMatcher(device='cpu', max_num_keypoints=10000, detection_threshold=0.0, nms_radius=4, border_dist=4, matcher_post_processing='ratio-test', matcher_thresh=0.8, **kwargs)[source][source]
Bases:
BaseMatcherSiLK matcher using standalone implementation. Reference: https://github.com/facebookresearch/silk
- Parameters:
device (str)
- MATCHER_POSTPROCESS_OPTIONS = ['ratio-test', 'mnn', 'double-softmax']