Viper: A Common Image Embedder Interface for Visual Place Recognition
This Python package provides a unified image embedder interface for visual place recognition (VPR), along with wrapper implementations of several state-of-the-art VPR models so they all expose the same API. It also includes a lightweight registry mechanism that lets you register custom embedders and retrieve them by string key.
Features
- Common
ImageEmbedderprotocol for VPR models (name, vector size, device, call semantics). - Eight wrapper models adapting popular VPR architectures to this interface:
- AnyLoc
- CliqueMining
- CosPlace
- EigenPlaces
- MegaLoc
- MixVPR
- NetVLAD
- SALAD
- Simple registry (
register_embedder_factory/get_embedder_factory) for instantiating embedders by key.
Installation
The package is configured as a standard Python project via pyproject.toml and adds support for the uv package manager.
You can install it in editable mode for development:
uv sync
Disclaimer: AnyLoc, CliqueMining, MegaLoc, and SALAD require CUDA to run.
Usage
Loading a built-in embedder
The recommended way to construct models is through the embedder registry.
import viper
factory: viper.ImageEmbedderFactory = viper.get_embedder_factory("salad") # or "mixvpr", "netvlad", "eigenplaces", ...
embedder: viper.ImageEmbedder = factory()
print(embedder.name) # "salad"
print(embedder.vector_size) # 8448
print(embedder.embedder_parameters) # dict of parameters
print(embedder.device) # "cpu" or "cuda"
All embedders implement the ImageEmbedder protocol, which exposes:
name: strvector_size: int(embedding dimension)embedder_parameters: dict[str, Any](model-specific metadata such as backbone, descriptor size, etc.)device: str(e.g."cpu"or"cuda:0")__call__(images: torch.Tensor) -> torch.Tensor(batched embedding,B x C x H x W -> B x E)
Embedding a batch of images
All wrappers expect a batch of images as a float tensor of shape B x C x H x W with values in [0.0, 1.0] (for NetVLAD this is explicitly asserted).
import torch
import viper
factory: viper.ImageEmbedderFactory = viper.get_embedder_factory("netvlad")
embedder: viper.ImageEmbedder = factory()
images: torch.Tensor = torch.rand(8, 3, 480, 640) # example batch, normalized to [0, 1]
embeddings: torch.Tensor = embedder(images) # shape: (8, embedder.vectorsize)
Wrappers handle grayscale input by converting 1-channel batches to 3-channel RGB internally. Some models also resize images so that height/width are multiples of 14, matching DINOv2 backbone constraints.
Registering a custom model
You can register your own model as long as it fulfills the ImageEmbedder interface.
import torch
from viper.registry import register_embedder_factory
from viper.types import ImageEmbedder
class MyEmbedder(torch.nn.Module):
@property
def name(self) -> str:
return "myembedder"
@property
def vector_size(self) -> int:
return 1024
@property
def embedder_parameters(self) -> dict:
return {"backbone": "resnet50"}
@property
def device(self) -> str:
return next(self.parameters()).device.type
def forward(self, images: torch.Tensor) -> torch.Tensor:
# return embeddings of shape B x 1024
...
# Factory that returns an ImageEmbedder instance
@register_embedder_factory(key="myembedder")
def load_myembedder() -> ImageEmbedder:
model = MyEmbedder()
return model
You can then retrieve a factory via get_embedder_factory("myembedder") like the built-in models.
Testing
The repository includes tests for the registry and embedder factories.[^10]
To run them:
uv run pytest
Acknowledgements
This package reuses ideas, code, and checkpoints from several excellent VPR projects. Please cite and credit the original works when using the corresponding models.
Metadata
Release files for libviper 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| libviper-0.2.0.tar.gz | 12.2 kB | Without provenance | Details for libviper-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libviper-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for libviper-0.2.0-py3-none-any.whl |
Total release size: 31.8 kB
Release files / libviper-0.2.0.tar.gz
| Download URL | libviper-0.2.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b37e57e1175e46b6544c5b275f9b597913f024f66053633ee0cd271b1d44e2b5
|
|
BLAKE2b-256 checksum How to use checksums |
88008591e32e272216230c11d33fd89d27f55b65c476e713f865da1304164484
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|
Release files / libviper-0.2.0-py3-none-any.whl
| Download URL | libviper-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ff750b328f71ab7b25f54981b9b708ffeb0c7fc5501dd3ec3a73fb1b1dedcd4
|
|
BLAKE2b-256 checksum How to use checksums |
117b09904aa4f10c0ba7ab8dbfd1ee2e9c3b38347d150877d04b49b14999af10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.14
|
Security for libviper 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.