Skip to main content

A package for visual place recognition (VPR) models.

Project description

Viper: A Common Image Embedder Interface for Visual Place Recognition

ci

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 ImageEmbedder protocol 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: str
  • vector_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libviper-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libviper-0.1.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file libviper-0.1.0.tar.gz.

File metadata

  • Download URL: libviper-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for libviper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 85e58c0ef1805a99e9656234ce2f3acdc101466b95d2f6ad04219729e0104118
MD5 360d80d5b36c54cf58b583472ece3b8d
BLAKE2b-256 760cf587d735b0cb4412f89b7460ad9ec707c263fff5182a78aae0eef2d3c705

See more details on using hashes here.

File details

Details for the file libviper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: libviper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.10

File hashes

Hashes for libviper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6882b644b5468b240e49d1a2090414b82a4153930fb4a1d07132554e2a1366d
MD5 7c32b188b4be4aeef17ad2a94ea94acd
BLAKE2b-256 81e118f5a0c4a9d95783e719adb3d1ac62354d6e0214d226a0905e91daca1676

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page