# KevinMusgrave/pytorch-metric-learning

The easiest way to use deep metric learning in your application. Modular, flexible, and extensible. Written in PyTorch.

Repository: https://github.com/KevinMusgrave/pytorch-metric-learning
Canonical: https://ross.abutalabs.com/products/pytorch-metric-learning
Homepage: https://kevinmusgrave.github.io/pytorch-metric-learning/
Language: Python
License: MIT
License Family: permissive
Topics: metric-learning, deep-learning, computer-vision, machine-learning, pytorch, deep-metric-learning, image-retrieval, self-supervised-learning, contrastive-learning, embeddings
Last push: 2025-08-17T17:08:48+00:00

## Health v2 (maintenance only)
Score: 48/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 37, release rhythm 31, longevity 100
- inputs: {"age_days": 2506, "days_push": 381, "days_rel": 381, "gap_med": 38, "n_releases_24m": 4}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 6339, forks 659 (observed 2026-08-28T04:09:41.836457+00:00)

## What it is
A PyTorch library providing modular losses, miners, samplers, and testers for deep metric learning. It supports building complete train/test workflows for learning embeddings, with composable components usable independently.

## Use cases
- train a model to learn image embeddings with triplet loss
- implement contrastive learning in PyTorch
- mine hard negative pairs for metric learning
- build an image retrieval system with deep embeddings
- train face recognition embeddings with ArcFace loss
- run self-supervised metric learning experiments
- evaluate embedding quality with retrieval metrics

## When to choose
- you need metric learning losses and miners in a PyTorch codebase
- you want a complete, modular train/test workflow for embedding learning
- you need well-tested implementations of losses like ArcFace, TripletMarginLoss, or MultiSimilarityLoss

## When to avoid
- you use TensorFlow, JAX, or another framework instead of PyTorch
- you only need off-the-shelf pretrained embeddings without training
- your task is standard classification rather than embedding learning

## Facets
- artifact type: library
- maturity: active
- function: machine-learning, deep-learning, computer-vision
- domain: machine-learning, deep-learning, computer-vision, image-processing
- platform: python, cross-platform
- tags: metric-learning, pytorch, contrastive-learning, embeddings, triplet-loss, image-retrieval, self-supervised-learning, loss-functions, hard-negative-mining, gpu

## Member repositories
- KevinMusgrave/pytorch-metric-learning (main) score 48

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:09:41.836457+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T17:46:08.871310+00:00, confidence not recorded.
  - readme: https://github.com/KevinMusgrave/pytorch-metric-learning (fetched 2026-08-28T04:09:41.836457+00:00, sha f43c5ab5b797)
  - homepage: https://kevinmusgrave.github.io/pytorch-metric-learning/ (fetched 2026-08-29T08:42:29.090212+00:00, sha e7b84ca1a101)
  - registry_pypi: https://pypi.org/pypi/pytorch-metric-learning/json (fetched 2026-08-29T08:42:29.099323+00:00, sha 03dd24c6b0e4)
- Data as of 2026-08-30T08:39:29.467469+00:00.
