Repository navigation
📋 Summary
Give your tracker eyes: reid turns detections into appearance embeddings so identities survive occlusions, crowds and people walking back into frame.
- Embed every box in a frame with one call on
sv.Detections. - Pick a pretrained encoder for pedestrians, MOT17, SportsMOT, DanceTrack or SoccerNet, or load your own from anywhere.
- Benchmark on Market-1501, MSMT17 or your own tracking crops with mAP, rank-k and mINP.
- Measure re-association: how well a model finds the same person again after a gap.
First release: pip install reid and go.
✨ Spotlights / highlights
Embeddings for tracker detections in one call
Name a pretrained model, pass your sv.Detections and the frame, and get one embedding per box. Compare them across frames to keep track of who is who. (#1, #7)
import numpy as np
import supervision as sv
from supervision.assets import VideoAssets, download_assets
from reid import ReIDModel
model = ReIDModel.from_pretrained("osnet_x1_0_msmt17_combineall")
frame = next(sv.get_video_frames_generator(download_assets(VideoAssets.PEOPLE_WALKING)))
detections = sv.Detections(xyxy=np.array([[746, 446, 828, 628], [1136, 502, 1214, 660]], dtype=np.float32))
embeddings = model.extract_embeddings(detections, frame)
embeddings.shape
# (2, 512)Load a model from anywhere, including tracking-tuned encoders
from_pretrained takes a curated name, an hf:// repo, a gd:// link, an http(s):// file or folder, a local weights file, or a folder you saved earlier. The catalog ships a general pedestrian model plus encoders fine-tuned for MOT17, SportsMOT, DanceTrack and SoccerNet. (#1, #7, #12, #22, #25)
from reid import ReIDModel, list_aliases
list_aliases()
model = ReIDModel.from_pretrained("osnet_x1_0_sportsmot")
model = ReIDModel.from_pretrained("https://example.com/models/my_model/")
model = ReIDModel.from_pretrained("weights.pth", architecture="osnet_x1_0")
model = ReIDModel("osnet_x0_25") # random weights, nothing downloaded
model.save("my_model") # weights.safetensors + reid_config.json
model = ReIDModel.from_pretrained("my_model")Benchmark on standard Re-ID datasets
evaluate ranks a gallery for every query and reports mAP, rank-1/5/10 and mINP. (#1, #7)
from reid import ReIDModel, load_market1501
model = ReIDModel.from_pretrained("osnet_x1_0_msmt17_combineall")
query, gallery = load_market1501("/path/to/Market-1501")
result = model.evaluate(query, gallery)
print(result.metrics)
# {'map': ..., 'rank1': ..., 'rank5': ..., 'rank10': ..., 'minp': ...}Measure re-association on your own tracking data
Cut MOT-format sequences into one folder per identity, then score how well the model picks the right person again gap_frames later. (#7)
from reid import ReIDModel, load_identity_folders
from reid.data.mot import generate_mot_patches
from reid.eval import ReassociationProtocol
model = ReIDModel.from_pretrained("osnet_x1_0_dancetrack")
generate_mot_patches(mot_root="/path/to/dancetrack/val", output_dir="/path/to/crops", split="full")
crops = load_identity_folders("/path/to/crops")
result = model.evaluate(crops, protocol=ReassociationProtocol(gap_frames=30, query_stride=60))
print(result.metrics)Compare embeddings yourself
distance_matrix is the same cosine or euclidean distance evaluate ranks with, ready for your own matching logic. (#11)
from reid import distance_matrix
query_embeddings = model.extract_embeddings(detections, frame)
gallery_embeddings = model.extract_embeddings(later_detections, later_frame) # must not be empty
closest = distance_matrix(query_embeddings, gallery_embeddings).argmin(axis=1)📝 Notable changes
🚀 Added
- Pretrained model loading —
ReIDModel.from_pretrained(source)from curated names,hf://,gd://,http(s)://files or folders, local weights, or saved folders. Weights must match the architecture, and pickle loading is refused forhttp(s)://weights. (#1, #7, #12, #22, #25) - Model building and saving —
ReIDModel(architecture)for random weights by name ortimm:<name>, or to wrap your ownnn.Module;save()round-trips throughfrom_pretrained. (#1, #7, #22) - Embedding extraction —
extract_embeddingsforsv.Detectionson a frame,extract_embeddings_from_pathsfor crops on disk. (#1, #7) - Evaluation —
ReIDModel.evaluatewithRetrievalProtocol(mAP, rank-k, mINP) andReassociationProtocol(rank-1, MRR); subclassEvaluationProtocolfor your own. (#1, #7) distance_matrix— the cosine or euclidean distancesevaluateuses, as a public function. (#11)- Datasets —
load_market1501,load_msmt17,load_identity_foldersandReIDSplit. (#1, #7) - MOT crops —
reid.data.mot.generate_mot_patchesturns MOT-format sequences into identity folders, with train/val half splits. (#7) - Model catalog —
list_aliases()with OSNet pedestrian weights, FastReID SBS for MOT17, and OSNet encoders tuned for MOT17, SportsMOT, DanceTrack and SoccerNet. (#1, #7, #12) - Architectures — OSNet x0.25 to x1.0, FastReID SBS ResNeSt-50, and any
timmbackbone;list_architectures(). (#1) - Preprocessing —
ReIDPreprocessingsaved with the model, resizing with PIL to match torchreid. (#1, #7) - Typed package for Python 3.10+. (#1, #6)
- Documentation at reid.roboflow.com: loading and evaluation guides, metrics explained with video and figures, API reference and tutorial notebooks. (#4, #5, #8, #9, #13, #14, #16)
🏆 Contributors
Thanks to everyone who built the first release of reid.
- Alexander Bodner (@AlexBodner, LinkedIn) — built the library: model loading, embeddings, evaluation protocols, MOT crops, tracking encoders and the documentation content
- Piotr Skalski (@SkalskiP, LinkedIn) — documentation site DNS on reid.roboflow.com
- Tomasz Stańczyk (@tstanczyk95, LinkedIn) — release preparation, technical supervision, guidance and expertise
- Jirka Borovec (@Borda, LinkedIn) — documentation site, packaging and PyPI publishing, CI and code quality
Automated contributions: @dependabot
Full changelog: https://github.com/roboflow/re-ID/commits/0.1.0