KevinMusgrave/pytorch-metric-learning

Train and evaluate embeddings for similarity search with PyTorch. Includes contrastive losses, hard example mining, samplers, and retrieval metrics.

What it solves

Building embedding models for tasks like retrieval, clustering, and recognition requires complex setups involving pair and triplet data. This library simplifies that process by providing ready-to-use building blocks for training embedding models.

How it works

It offers composable PyTorch components—such as losses, hard-example miners, distances, reducers, and regularizers—that you can plug directly into your own training loops. Your model outputs embeddings, and the library's components handle operations like pulling positive pairs together and pushing negatives apart.

Who it’s for

It is designed for machine learning developers and researchers working with PyTorch who need to train embedding models for similarity learning, image or data retrieval, clustering, and classification.

Highlights

  • Composable losses, miners, distances, reducers, and regularizers
  • Compatible with standard PyTorch training loops
  • Optional integrations with Faiss for retrieval and scikit-learn for clustering metrics
  • Core package relies only on PyTorch and NumPy

Related

  • Project
  • Project
  • Project
  • Project
  • Project