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(logits[, ...])

Extract keypoints from detector logits.

load_silk_model(weights_path[, device])

Load SiLK model from safetensors.

match_descriptors_mnn(desc0, desc1[, ...])

Match descriptors using mutual nearest neighbors with optional ratio test.

sample_descriptors(descriptors, keypoints[, ...])

Sample descriptors at keypoint locations.

simple_nms(scores[, radius])

Non-maximum suppression on a 2D score map.

Classes

DescriptorHead([in_channels, out_channels])

Descriptor head: outputs dense descriptors.

DetectorHead([in_channels])

Detector head: outputs logits for keypoint detection.

SiLKModel([descriptor_dim])

Self-supervised Interest point Learning with Keypoints (SiLK).

SilkMatcher([device, max_num_keypoints, ...])

SiLK matcher using standalone implementation.

VGGBackbone()

VGG-style backbone for SiLK.

VGGBlock(in_channels, out_channels[, ...])

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: Module

A 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 Module instance 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: Module

VGG-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 Module instance 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: Module

Detector 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 Module instance 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: Module

Descriptor 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 Module instance 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: Module

Self-supervised Interest point Learning with Keypoints (SiLK).

forward(x)[source][source]

Run SiLK model forward pass.

Parameters:

x (torch.Tensor) – (B, 1, H, W) grayscale image

Returns:

(logits, descriptors) where:
  • logits (torch.Tensor): (B, 1, H, W) detector logits

  • descriptors (torch.Tensor): (B, C, H, W) descriptor map

Return type:

tuple

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: BaseMatcher

SiLK matcher using standalone implementation. Reference: https://github.com/facebookresearch/silk

Parameters:

device (str)

MATCHER_POSTPROCESS_OPTIONS = ['ratio-test', 'mnn', 'double-softmax']
preprocess(img)[source][source]

Convert to grayscale and add batch dimension if needed.