Person re-identification
OSNet-AIN x1.0
Recognizes the same person again across frames and cameras from their appearance: a 512-number descriptor per person, from a 2.2-million-parameter network.
About this model
Re-identification answers "have I seen this person before?". Give it a crop of a person from a detector and it returns 512 numbers describing their appearance (clothing, colors, build, carried bags); two crops of the same person give similar descriptors, two different people give different ones. Compare descriptors with cosine similarity to follow people through a scene, keep track of them when they are hidden for a moment, or match them across cameras.
OSNet (omni-scale network) is a small network built for this task; the AIN variant adds instance normalization so it holds up on cameras it was not trained on. This pack is torchreid's osnet_ain_x1_0 trained on the MSMT17 dataset (all of it), the setting that generalizes best to new cameras among the published models.
Slab stretches the crop to 128 x 256 pixels as torchreid does; the app crops each detector box with Frame.crop (no copy).
What you can build
- Count people across several cameras without counting the same person twice
- Keep a person's identity in a tracker through occlusions and missed detections
- Measure how people move through a space (shops, stations) without storing images
The same people 2 seconds later
f16Raysonho @ Open Grid Scheduler / Grid Engine, CC0, https://commons.wikimedia.org/wiki/File:DiagonalCrosswalkYongeDundas.webm (frames)
People found by YOLO26n in two frames 2 s apart (8 and 8), described by OSNet-AIN on Apple Neural Engine (FP16) and paired by cosine similarity, most similar first, each person used once. Pairs at 0.7 or more are drawn: 0.88, 0.74, 0.80. Every drawn pair is the same person; pairs below 0.7 in these frames were often not.
The same people 2 seconds later
f16Raysonho @ Open Grid Scheduler / Grid Engine, CC0, https://commons.wikimedia.org/wiki/File:DiagonalCrosswalkYongeDundas.webm (frames)
People found by YOLO26n in two frames 2 s apart (8 and 7), described by OSNet-AIN on Apple Neural Engine (FP16) and paired by cosine similarity, most similar first, each person used once. Pairs at 0.7 or more are drawn: 0.70, 0.75, 0.86, 0.79, 0.89. Every drawn pair is the same person; pairs below 0.7 in these frames were often not.
Variants & downloads
Choose the build for your appModel files are hosted on Google Drive. Large files may open a confirmation page before downloading.
Small
SlabWeights stored as int8 in blocks of 64, decoded to float when loading. A fifth smaller; descriptors move slightly more (see Accuracy).
Platforms: macos · android
osnet-ain-x1-0-int8.slab
5.9 MB · Hosted download
SHA-256 checksum
f8c98c8c7953381deb1fade60d6d1dfdbac02e02b58fb140a258cc2bd5582dd0LICENSE-torchreid.txt
1 KB
SHA-256 checksum
59489828935ddd817677a2477b849222502fe1c365c2fc69387ac14afe379b9eConversion details
- command
- git clone https://github.com/KaiyangZhou/deep-person-reid && git -C deep-person-reid checkout f8cd150fdf77e8d9e1ed143b7f308c2c609ded50 gdown 1SigwBE6mPdqiJMqhuIY4aqC7--5CsMal -O osnet_ain_x1_0_msmt17.pth python -c "import importlib.util, torch; s = importlib.util.spec_from_file_location('osnet_ain', 'deep-person-reid/torchreid/models/osnet_ain.py'); o = importlib.util.module_from_spec(s); s.loader.exec_module(o); m = o.osnet_ain_x1_0(num_classes=1, pretrained=False, loss='softmax'); sd = torch.load('osnet_ain_x1_0_msmt17.pth', map_location='cpu', weights_only=False); sd = sd.get('state_dict', sd); m.load_state_dict({k.replace('module.', ''): w for k, w in sd.items() if not k.replace('module.', '').startswith('classifier')}, strict=False); torch.onnx.export(m.eval(), torch.zeros(1, 3, 256, 128), 'model.onnx', input_names=['image'], output_names=['features'], opset_version=17, dynamo=False)" slab-load convert model.onnx model.slab --input image=1x3x256x128 --meta task=embed --meta resize=stretch --meta interpolation=bilinear --meta antialias:bool=true --meta normalize=imagenet --meta color=rgb slab-load quantize model.slab osnet-ain-x1-0-int8.slab slab-load meta set osnet-ain-x1-0-int8.slab default_backend.macos=npu
Integration examples
Python
python
import slab
cfg = slab.Config(cache_dir="/tmp/slab_cache", license=open("license.slablic.txt").read())
detector = slab.Session(cfg, "yolo26n-f16.slab") # any person detector
reid = slab.Session(cfg, "osnet-ain-x1-0-f16.slab")
def people(path):
frame = slab.Frame.open(path)
out = []
for b in detector.run(slab.Input(frame=frame)).boxes(score_threshold=0.5, iou_threshold=1.0):
if b.label != "person":
continue
x, y = int(max(b.x1, 0)), int(max(b.y1, 0))
crop = frame.crop(x, y, int(min(b.x2, frame.width)) - x, int(min(b.y2, frame.height)) - y)
d = reid.run(slab.Input(frame=crop))
d.normalize_l2()
out.append(d)
return out
before, after = people("frame1.jpg"), people("frame2.jpg")
for i, p in enumerate(before):
best = max(range(len(after)), key=lambda j: p.cosine_similarity(after[j]))
s = p.cosine_similarity(after[best])
print(i, "->", best if s >= 0.7 else "no match", round(s, 2))
Device & backend compatibility
Pack default: macos / NPU. Fastest per person by far: 1.2 ms against 6.9 ms on the GPU, which matters with many people per frame. It prepares in about 2 s, once.
| Platform | Engine | Status | Precision |
|---|---|---|---|
| apple | CPU CPU | Supported Measured on macOS. | f32 |
| apple | Metal GPU | Supported Measured on macOS. | f32 |
| apple | Apple Neural Engine NPU | Supported Measured on macOS. The default; computes in FP16. | f16 |
| android | CPU CPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Vulkan GPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. | f32 |
| android | Qualcomm Hexagon NPU (QNN) NPU | Supported Measured on a Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2, Adreno 740), Android 17. The NPU computes in FP16 (the int8 pack's weights are widened to FP16). | f16 |
Performance
Results depend on the device, runtime, and test conditions. Each measurement keeps its own context.
Mac with Apple M1 Max
Slab · CPU
macOS 26.6.2
22.8 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). One person cropped from a 1920 x 1080 frame (Frame.crop, resizing included): 22.83 ms median of 100.
Mac with Apple M1 Max
Slab · GPU
macOS 26.6.2
4.7 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). One person cropped from a 1920 x 1080 frame (Frame.crop, resizing included): 6.25 ms median of 100.
Mac with Apple M1 Max
Slab · NPU
macOS 26.6.2
0.9 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). One person cropped from a 1920 x 1080 frame (Frame.crop, resizing included): 1.23 ms median of 100.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · CPU
Android 17
40.2 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). open_ms: opening the session. Peak memory (resident) after the runs: 68 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · GPU
Android 17
17.1 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). open_ms: opening the session with the GPU programs already in the cache folder (the first open on a device compiles them, about 0.3 s more). Peak memory (resident) after the runs: 78 MB.
Samsung Galaxy S23 Ultra (Snapdragon 8 Gen 2)
Slab · NPU
Android 17
2.0 ms
Measured time · scope below
Median of 100 warm runs of the model (Slab's run time). open_ms: opening the session, including preparing the model for the Hexagon NPU. Peak memory (resident) after the runs: 73 MB.
Accuracy checks
macos · CPU · int8
The upstream PyTorch model (torchreid at f8cd150fdf77) with torchreid's test transform (PIL bilinear resize to 256 x 128, ImageNet normalization) on 148 people found by the YOLO26n pack in 28 frames of a CC0 street video (one frame every 2 s)
Cosine similarity to the upstream descriptor 0.999022 on average, 0.997729 at worst. Matching each person to the most similar person 2 s later gives the same choice as upstream for 141 of 142.
macos · GPU · int8
The upstream PyTorch model (torchreid at f8cd150fdf77) with torchreid's test transform (PIL bilinear resize to 256 x 128, ImageNet normalization) on 148 people found by the YOLO26n pack in 28 frames of a CC0 street video (one frame every 2 s)
Cosine similarity to the upstream descriptor 0.999022 on average, 0.997729 at worst. Matching each person to the most similar person 2 s later gives the same choice as upstream for 141 of 142.
macos · NPU · int8
The upstream PyTorch model (torchreid at f8cd150fdf77) with torchreid's test transform (PIL bilinear resize to 256 x 128, ImageNet normalization) on 148 people found by the YOLO26n pack in 28 frames of a CC0 street video (one frame every 2 s)
Cosine similarity to the upstream descriptor 0.998913 on average, 0.997639 at worst. Matching each person to the most similar person 2 s later gives the same choice as upstream for 142 of 142.
android · NPU · int8
Slab's CPU engine (FP32) on the same 1920 x 1080 photo
Cosine similarity of the output with the CPU's: 0.99769.
Before you choose this model
- Training data for non-commercial research (see License).
- Descriptors of people are personal data under laws such as the GDPR: get legal advice before storing or matching them, and do not use the model to identify people.
- Appearance only: a change of clothes, a coat taken off or very different lighting breaks it; it is not face recognition.
- Similarity needs a threshold of your own: in our street footage, pairs at 0.7 or more were the same person and pairs below were often not.
- It needs a person detector first, and small crops (under about 90 pixels tall) describe people poorly.
- On the Neural Engine the first open takes about 2 s to prepare the model.