opr.modules package

Building blocks for the OPR modular system.

opr.modules.cosplace

CosPlace aggregation layer implementation.

class opr.modules.cosplace.CosPlace(in_dim: int, out_dim: int)[source]

Bases: Module

CosPlace aggregation layer.

As implemented in https://github.com/gmberton/CosPlace/blob/main/model/network.py

forward(x: Tensor) Tensor[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.

opr.modules.cross_attention

opr.modules.eca

Implementation of Efficient Channel Attention ECA block.

Wang, Qilong, et al. “ECA-Net: Efficient channel attention for deep convolutional neural networks.” Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. 2020.

Paper: https://arxiv.org/abs/1910.03151 Code for Mink version adopted from the repository: https://github.com/jac99/MinkLoc3Dv2, MIT License

class opr.modules.eca.MinkECABasicBlock(*args: Any, **kwargs: Any)[source]

Bases: BasicBlock

Efficient Channel Attention BasicBlock for ResNet with MinkowskiEngine.

forward(x: object) object[source]

Forward pass of ECA BasicBlock.

Parameters:

x – Input sparse tensor from MinkowskiEngine.

Returns:

Output sparse tensor with ECA attention applied.

class opr.modules.eca.MinkECALayer(channels: int, gamma: int = 2, b: int = 1)[source]

Bases: Module

Efficient Channel Attention layer for sparse tensors with MinkowskiEngine.

forward(x: object) object[source]

Forward pass of ECA layer.

Parameters:

x – Input sparse tensor from MinkowskiEngine.

Returns:

Output sparse tensor with attention applied.

opr.modules.fusion

Basic fusion modules implementation.

class opr.modules.fusion.Add[source]

Bases: Module

Addition module.

forward(data: Dict[str, Tensor]) Tensor[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 opr.modules.fusion.Concat[source]

Bases: Module

Concatenation module.

forward(data: Dict[str, Tensor]) Tensor[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 opr.modules.fusion.GeMFusion(p: int = 3, eps: float = 1e-06)[source]

Bases: Module

GeM fusion module.

forward(data: Dict[str, Tensor]) Tensor[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.

opr.modules.gem

Generalized-Mean pooling layer implementation.

Radenović, Filip, Giorgos Tolias, and Ondřej Chum. “Fine-tuning CNN image retrieval with no human annotation.” IEEE transactions on pattern analysis and machine intelligence 41.7 (2018): 1655-1668.

Paper: https://arxiv.org/abs/1711.02512 Code adopted from the repository: https://github.com/jac99/MinkLocMultimodal, MIT License

class opr.modules.gem.GeM(p: int = 3, eps: float = 1e-06)[source]

Bases: Module

GeM pooling layer.

forward(x: Tensor) Tensor[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 opr.modules.gem.GlobalAvgPooling[source]

Bases: Module

Global average pooling fusion module.

forward(x: Tensor) Tensor[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 opr.modules.gem.GlobalMaxPooling[source]

Bases: Module

Global max pooling fusion module.

forward(x: Tensor) Tensor[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 opr.modules.gem.MinkGeM(p: int = 3, eps: float = 1e-06)[source]

Bases: Module

GeM pooling layer for sparse tensors with MinkowskiEngine.

forward(x: object) Tensor[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.

sparse: bool = True
class opr.modules.gem.SeqGeM(p: int = 3, eps: float = 1e-06)[source]

Bases: GeM

1D GeM pooling layer.

opr.modules.mixvpr

MixVPR: Feature Mixing for Visual Place Recognition.

Source: https://github.com/amaralibey/MixVPR/blob/main/models/aggregators/mixvpr.py

class opr.modules.mixvpr.FeatureMixerLayer(in_dim: int, mlp_ratio: float = 1.0)[source]

Bases: Module

Feature Mixer Layer.

forward(x: Tensor) Tensor[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 opr.modules.mixvpr.MixVPR(in_channels: int = 256, in_h: int = 10, in_w: int = 18, out_channels: int = 128, mix_depth: int = 4, mlp_ratio: float = 1, out_rows: int = 2)[source]

Bases: Module

MixVPR aggregation layer.

Source: https://github.com/amaralibey/MixVPR/blob/main/models/aggregators/mixvpr.py

forward(x: Tensor) Tensor[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.

opr.modules.mlp

2-layer MLP module implementation.

class opr.modules.mlp.MLP(in_features: int, hidden_features: int | None = None, out_features: int | None = None, act_layer: str = 'gelu', bias: bool = True, drop: float = 0.0, use_conv: bool = False)[source]

Bases: Module

MLP as used in Vision Transformer, MLP-Mixer and related networks.

forward(x: Tensor) Tensor[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.

opr.modules.netvlad

NetVLAD layer implementation.

class opr.modules.netvlad.NetVLAD(num_clusters: int = 64, dim: int = 128, normalize_input: bool = True, vladv2: bool = False)[source]

Bases: Module

NetVLAD layer implementation.

forward(x: Tensor) Tensor[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.

init_params(clsts: ndarray, traindescs: ndarray) None[source]

Initialize NetVLAD layer parameters.

opr.modules.self_attention

Self-attention modules.

class opr.modules.self_attention.SelfAttention(embed_size: int)[source]

Bases: Module

Self-attention module.

forward(x: Tensor | Dict[str, Tensor]) Tensor | Dict[str, Tensor][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.

opr.modules.svt

Implementation of ASVT and CSVT modules.

Citation:

Fan, Zhaoxin, et al. “Svt-net: Super light-weight sparse voxel transformer for large scale place recognition.” Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 36. No. 1. 2022.

Source: https://github.com/ZhenboSong/SVTNet Paper: https://arxiv.org/abs/2105.00149

class opr.modules.svt.ASVT(in_dim: int, reduction: int = 8)[source]

Bases: Module

ASVT - Atom-Based Sparse Voxel Transformer.

forward(x: MinkowskiEngine.SparseTensor) MinkowskiEngine.SparseTensor[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 opr.modules.svt.CSVT(channels: int, num_tokens: int = 16)[source]

Bases: Module

CSVT - Cluster-Based Sparse Voxel Transformer.

forward(x: MinkowskiEngine.SparseTensor) MinkowskiEngine.SparseTensor[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.