KevinMusgrave/pytorch-metric-learning
KevinMusgrave/pytorch-metric-learning has 6,342 GitHub stars and 663 forks. GitHot measured -1 in 7 days and -1 in 15 days. Last checked 2026-11-10 03:24 UTC. Last push 2026-11-01.
PyTorch를 사용해 유사도 검색을 위한 임베딩을 학습하고 평가합니다. 대조 손실, 어려운 예제 마이닝, 샘플러, 검색 평가 지표를 제공합니다.
측정된 스타 증가
- in 24h
- 업데이트 지연
- in 7 days
- -1
- in 15 days
- -1
- in 1 month
- 업데이트 지연
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
Train embedding models with composable PyTorch losses, hard-example miners, distances, reducers, and regularizers. Use them in your own training loop for retrieval, clustering, recognition, or learning from pairs and triplets.
Docs for humans · Documentation source
Install
Install from PyPI with uv or pip:
uv pip install pytorch-metric-learning
pip install pytorch-metric-learning
The core package needs only PyTorch and NumPy. Optional extras add the Faiss
retrieval backend, pytorch-metric-learning[faiss], and scikit-learn for the
NMI/AMI clustering metrics, pytorch-metric-learning[clustering].
Version 3 requires Python 3.12 or newer, PyTorch 2.14.0 or newer, and NumPy 2.5.3 or newer. Upgrading from version 2? Read the release notes and look up old names in the migration guide. The version 2 documentation remains available.
A minimal training step
Your model produces one embedding per input. Equal labels identify positive pairs; different labels identify negatives. Here a contrastive loss pulls positive pairs together and pushes negatives apart:
import torch
from pytorch_metric_learning import losses
torch.manual_seed(17)
model = torch.nn.Linear(8, 4)
optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
data = torch.randn(12, 8)
labels = torch.arange(4).repeat_interleave(3)
loss_func = losses.ContrastiveLoss(neg_margin=1.4)
optimizer.zero_grad(set_to_none=True)
loss = loss_func(model(data), labels)
loss.backward()
optimizer.step()
The model returns embeddings shaped (12, 4) and labels have shape (12,).
This loss L2-normalizes embeddings by default. It averages active positive and
negative pair penalties separately, then adds them. See the
contrastive-loss contract for distances,
margins, and reduction options.
Learn more
The documentation starts with a task index and a concepts overview of embeddings, tuples, distances, loss terms, and reducers. Every component page states its signature, defaults, tensor contract, and paper, and the recipes show complete training and evaluation code.
Contributing
See CONTRIBUTING.md. Thanks to all contributors, upstream projects, and supporters.
Citing this library
If you use this library in your research, please cite the PyTorch Metric Learning paper:
@article{Musgrave2020PyTorchML,
title={PyTorch Metric Learning},
author={Kevin Musgrave and Serge J. Belongie and Ser-Nam Lim},
journal={ArXiv},
year={2020},
volume={abs/2008.09164}
}
관련 프로젝트 살펴보기
tensorflow/tensorflow
모두를 위한 오픈소스 머신러닝 프레임워크
201,427 스타huggingface/transformers
🤗 Transformers: 텍스트, 비전, 오디오, 멀티모달 분야의 최첨단 머신러닝 모델을 위한 모델 정의 프레임워크로, 추론과 학습을 모두 지원합니다.
168,711 스타AUTOMATIC1111/stable-diffusion-webui
Stable Diffusion 웹 UI
165,289 스타Comfy-Org/ComfyUI
그래프와 노드로 구성된 인터페이스를 갖춘, 가장 강력하고 모듈성이 뛰어난 확산 모델 GUI, API, 백엔드입니다. 세계에서 가장 빠른 로컬 추론 엔진입니다.
146,271 스타