🚗
AIMS Coursework
Vehicle Re-Identification
Late 2024 — ResNet50 + Triplet Loss on VeRi Dataset
ResNet50
Triplet Loss
Semi-Hard Mining
Metric Learning
About
A vehicle re-identification system using the VeRi dataset. Leveraging a pre-trained ResNet50 with triplet loss to learn embeddings that group same-vehicle images together while separating different vehicles.
View on GitHub →Model Architecture
ResNet50 + Embedding Layer
- • Pre-trained ResNet50 for feature extraction
- • Custom 256-dimensional embedding layer as output
- • Images resized to 224×224, normalized with ImageNet stats
Triplet Loss:
Loss = max(0, dist(anchor, positive) - dist(anchor, negative) + margin)
Margin (α) = 0.3 | Optimizer: Adam (LR = 1e-4)
Triplet Mining Strategies
Random Offline Mining
- • Generated 37,000 triplets total
- • Sampled 10,000 for training
- • 10 epochs, batch size 64
Semi-Hard Online Mining ⭐
- • P identities × K images per batch
- • Select semi-hard negatives on-the-fly
- • More informative triplets
Results
| Strategy | Config | mAP |
|---|---|---|
| Random Mining | 10K triplets, 10 epochs | 17.33% |
| Semi-Hard Mining ⭐ | P=4, K=4, 20 epochs | 36.21% |
2x improvement with semi-hard mining over random!
Random Mining: Query Results
Semi-Hard Mining (P=4, K=4): Query Results
Larger Batch Semi-Hard (P=8, K=4): Query Results
Key Takeaways
- ✅ Semi-hard mining is critical — 2x better than random (36% vs 17% mAP)
- ✅ Informative triplets dramatically improve embedding quality
- ✅ Larger batch sizes (P=8) can further improve results
- ✅ Future work: Fine-tune ResNet, add attention mechanisms