Skip to main content

Crate loftr

Crate loftr 

Source
Expand description

Native Rust/tch LoFTR feature matching.

This crate exposes a small, high-level API for constructing a LoFTR model, loading compatible weights, and matching a pair of images.

Typical usage:

  1. Build a LoftrModel with a preset LoftrConfig.
  2. Load exported weights with LoftrModel::load_weights.
  3. Run LoftrModel::forward or LoftrModel::forward_debug.

The published docs are built with the doc-only feature so they can render on docs.rs without linking libtorch. For local runs, either point tch at an existing libtorch install or enable the download-libtorch feature.

§Example

use loftr::{LoftrConfig, LoftrModel};
use tch::{Device, Kind, Tensor};

let mut model = LoftrModel::new(Device::Cpu, LoftrConfig::outdoor())?;
model.load_weights("artifacts/weights/loftr_outdoor_state_dict.safetensors")?;

let image0 = Tensor::rand([1, 1, 128, 128], (Kind::Float, Device::Cpu));
let image1 = Tensor::rand([1, 1, 128, 128], (Kind::Float, Device::Cpu));
let matches = model.forward(&image0, &image1)?;

println!("match count = {}", matches.confidence.size()[0]);

Structs§

CoarseDebugStats
Summary statistics for coarse-stage matching outputs.
FineConfig
Transformer parameters for the fine matching refinement stage.
LoftrConfig
High-level LoFTR model configuration.
LoftrDebugStages
Debug-stage summary returned by LoFTRModel::forward_debug.
LoftrMatches
Matched keypoints and confidences returned by LoFTR inference.
LoftrModel
LoFTR model instance with owned weights and inference state.
MatchCoarseConfig
Matching parameters for the coarse LoFTR correspondence stage.
ResNetFpnConfig
Backbone parameters for the ResNetFPN encoder used by LoFTR.
TensorDebugStats
Summary statistics for a tensor captured during debug inference.
TransformerConfig
Transformer parameters shared by LoFTR coarse and fine stages.

Enums§

AttentionType
Attention implementations supported by the LoFTR transformers.
BackboneType
Backbone variants supported by this crate.
LoftrError
Errors returned by the public loftr API.
MatchType
Coarse matcher implementations supported by this crate.
TransformerLayer
Transformer layer ordering used by LoFTR encoder stacks.

Functions§

normalize_loftr_image
Converts supported LoFTR image layouts into normalized [B, 1, H, W] tensors.