MobileNetV2 + GeM + Batch-Hard Quadruplet — Turtle Re-Identification (Combined Datasets)
A re-identification embedding model for individual sea-turtle recognition. It maps a turtle
photo to a 512-d L2-normalisable embedding; identity is decided by nearest-neighbour retrieval
(cosine / Euclidean on the unit sphere) against a labelled gallery. Trained jointly on the
heads-crop SeaTurtleID2022 set plus two additional sea-turtle datasets (Amvrakikos, Reunion) so
the learned embedding generalises across photography conditions and populations.
This is a reproduction of the SeaTurtleID2022 re-id protocol using a MobileNetV2 backbone
(not the paper's Swin-B/ArcFace), trained with batch-hard quadruplet loss and
WeightedMPerClassSampler — deliberately a small, fully-trainable backbone with a metric
loss, to show how far that recipe reaches.
This checkpoint corresponds to the combined multi-species (Experiment 2) model in the
accompanying paper. It is the only released checkpoint; the single-species Experiment 1 model
is not released. Every number reported on this card is reproducible from the shipped
eval.py and model.py (no project code required): load the weights from the Hub with
MobileNetV2ReID.from_pretrained and run python eval.py to recompute the Results table
below under the closed-set train-gallery k-NN protocol with 10-crop TTA at 384.
Model
- Architecture: MobileNetV2 (fully unfrozen) → Generalized Mean pooling (GeM, p=3.0 learnable)
→ Linear(1280→512) → LayerNorm → ReLU → Dropout(0.3)
- Embedding dim: 512 (L2-normalise before retrieval)
- Input resolution: 384×384 (centre-crop at eval; resize→random-crop at train)
- Loss: batch-hard quadruplet (top-k=6 soft-hard mining; alpha=0.3, beta=0.1)
- Sampler: WeightedMPerClassSampler (m=4 instances per identity per batch)
- Batch size: 128 (32 classes/batch → 124 negatives/anchor; larger batch both lifted R@1 and
collapsed seed variance ~8× vs the v7 batch-64 config)
- Schedule: 150 epochs, LinearLR 5-epoch warmup → CosineAnnealingWarmRestarts(T_0=75, T_mult=2),
base LR 1.4e-4 (scaled ~√2 from 1e-4 to offset fewer optimizer steps at batch 128), AMP (fp16)
- Eval-time augmentation: 10-crop TTA (FiveCrop + horizontal flip → 10 passes, averaged on the
unit sphere)
Loading
The model class ships with the repo as model.py (self-contained, no project
dependency). PyTorchModelHubMixin reconstructs the model from config.json;
only embedding_dim is a constructor kwarg, the rest are metadata. The
pretrained backbone weights are re-fetched at construction, then overwritten by
the Hub state_dict on from_pretrained.
1import torch
2from model import MobileNetV2ReID # model.py ships on this repo
3
4# Load weights straight from the Hub:
5model = MobileNetV2ReID.from_pretrained(
6 "marcmarais-ru/seaturtle_reid_mobilenetv2-quadruplet-random-combined_datasets",
7 embedding_dim=512, # must match the trained dim
8)
9model.eval().cuda()
10
11# Eval transform: resize so the shorter/a side hits 384, then centre-crop.
12eval_transform = T.Compose([
13 T.Resize((384, 384)), # SeaTurtleID2022 heads are near-square; resize is fine
14 T.ToTensor(),
15 T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
16])
Retrieval recipe
Closed-set re-id, k-NN against a labelled gallery (gallery = train split, query = test split).
Embeddings are not pre-normalised, so normalise before any distance:
1with torch.no_grad():
2 emb = model(eval_transform(image).unsqueeze(0).cuda())
3emb = torch.nn.functional.normalize(emb, p=2, dim=1) # L2-normalise -> cosine == dot product
4# gallery_emb likewise L2-normalised; nearest neighbour = argmax(emb @ gallery_emb.T)
For the full test-time setup (10-crop TTA, closed-set guard dropping unclosed query identities,
Recall@1/5), see the Project_Code.py source: compute_embeddings_tta and compute_recall_at_k.
Datasets used (training)
The model is trained on the union of three sea-turtle re-id datasets, all drawn from the
wildlifedatasets loader under Data/wildlifedatasets/:
| Dataset (folder) | Role | Notes |
|---|
seaturtleidheads (v3) | Heads-crop SeaTurtleID2022 | Primary; 233 identities, heads only |
amvrakikosturtles (v1) | Amvrakikos Gulf turtles | Greek population, distinct photography |
reunionturtles (v1) | Reunion Island turtles | Indian-Ocean population, distinct photography |
Identities are merged across datasets via a global_id mapping so an individual in one dataset
never collides with one in another. The split is the published split_closed_random column
(random closed-set split — no identity appears in both train and test).
Reference for the SeaTurtleID2022 protocol: SeaTurtleID2022: A Large-Scale Re-Identification
Benchmark for Sea Turtles (arXiv 2211.10307). The paper reports results with a Swin-B + ArcFace
backbone; this model is the MobileNetV2 + quadruplet reproduction of that protocol.
Results (test, random split, 384-res + 10-crop TTA)
Reported as mean ± std over 3 seeds (batch 128, top-k=6, lr 1.4e-4); the published
checkpoint is the best seed of that sweep (seed 2026, Overall R@1 0.7200). The data
split is held fixed across seeds (SeaTurtleID2022 published split_closed_random +
deterministic ClosedSetSplit for Amvrakikos/Reunion), so variance reflects
weight-init / augmentation / sampler draw only.
| Target split | R@1 (mean ± std, n=3) | R@5 (mean ± std, n=3) |
|---|
| Overall Cross-Dataset | 0.7166 ± 0.0036 | 0.7722 ± 0.0056 |
| Sea Turtle (Heads Crop) | 0.7344 ± 0.0051 | 0.7880 ± 0.0051 |
| Amvrakikos | 0.3267 ± 0.0462 | 0.4400 ± 0.0200 |
| Reunion | 0.4762 ± 0.0119 | 0.5516 ± 0.0182 |
All numbers are closed-set Recall@1/5 with the closed-set guard applied (unclosed query identities
dropped from scoring). Compare to the paper's Swin-B + ArcFace on the heads random split
(R@1 0.872); this MobileNetV2 + quadruplet model reaches 0.734 on heads under the same
protocol — a deliberately smaller backbone reaching a large fraction of the Swin-B result.
Variance note: the batch-128 config collapsed seed variance ~8× vs the earlier batch-64
config (Overall R@1 std 0.029 → 0.004). R@5 is near its ceiling (R@5−R@1 gap ≈ 0.06, matching the
paper's ~0.07): doubling the negative pool and mined negatives (top-k 3→6) lifted R@1 but moved R@5
by only ~0.002, indicating R@5 is backbone/loss-capacity-limited rather than mining-limited. See the
source for the full per-seed breakdown and the v7 batch-64 baseline.
Per-species breakdown (published seed, 10-crop TTA @384)
Recall@1/5 partitioned by species within the combined test query set, against
the same combined 10-crop TTA gallery used for the headline numbers above
(comparable to the headline table; NOT multi-seed means). Loggerhead is the
heads-crop SeaTurtleID2022 test set plus the Amvrakikos test set; Green and
Hawksbill are the Reunion test set filtered by its Species column.
| Species | n images | R@1 | R@5 |
|---|
| Loggerhead | 2281 | 0.7290 | 0.7849 |
| Green | 50 | 0.5000 | 0.5600 |
| Hawksbill | 34 | 0.4412 | 0.5882 |
Green (n=50) and Hawksbill (n=34) are small per-species partitions, so their
per-species R@1/R@5 are noisy point estimates (one image ≈ 0.020 / 0.029 of
R@1 respectively); Loggerhead (n=2281) is the trustworthy per-species figure.
The per-species R@1 values are lower-bounded by — and aggregate up to — the
headline Overall R@1: weighted across species they reconstruct the published
Overall R@1 (0.721 for seed 2026).
Intended use & limitations
- Intended: individual animal re-identification research / benchmarks, closed-set retrieval.
- Not intended: open-set detection of unseen individuals, human identification, or any use
outside wildlife research.
- Limitations: trained on three sea-turtle populations only; generalisation to other taxa or
unseen photography conditions is unverified. Closed-set protocol assumes the query individual is
present in the gallery. Time-aware split performance is much lower (time-overfitting); see the
source paper and code for that regime's caveats.
Citation
If you use this model, please cite the SeaTurtleID2022 and WildlifeDatasets papers and this reproduction:
1@INPROCEEDINGS {10484106,
2author = { Adam, Lukas and Cermak, Vojtech and Papafitsoros, Kostas and Picek, Lukas },
3booktitle = { 2024 IEEE/CVF Winter Conference on Applications of Computer Vision (WACV) },
4title = {{ SeaTurtleID2022: A long-span dataset for reliable sea turtle re-identification }},
5year = {2024},
6volume = {},
7ISSN = {},
8pages = {7131-7141},
9doi = {10.1109/WACV57701.2024.00699},
10url = {https://doi.ieeecomputersociety.org/10.1109/WACV57701.2024.00699},
11publisher = {IEEE Computer Society},
12address = {Los Alamitos, CA, USA},
13month =Jan}
14
1@inproceedings{vcermak2024wildlifedatasets,
2 author = {Cermak, Vojtech and Picek, Lukas and Adam, Lukas and Papafitsoros, Kostas},
3 booktitle = {2024 IEEE/CVF Winter Conference on Applications of Computer Vision (WACV)},
4 title = {WildlifeDatasets: An open-source toolkit for animal re-identification},
5 year = {2024},
6 pages = {5941-5951},
7 doi = {10.1109/WACV57701.2024.00585},
8 publisher = {IEEE Computer Society}
9}
1@misc{mobilenetv2-quadruplet-turtles,
2 title = {MobileNetV2 + GeM + batch-hard quadruplet turtle re-identification (combined datasets)},
3 author = {Marc Marais},
4 year = {2026},
5 howpublished = {\url{https://huggingface.co/marcmarais-ru/seaturtle_reid_mobilenetv2-quadruplet-random-combined_datasets}}
6}