Academic guide8 min read
Person ReID Loss Functions: Triplet, ArcFace and ID Loss
Compare identity classification, batch-hard triplet loss, ArcFace and metric-learning objectives for Person ReID, with formulas and trade-offs.
Three crops enter a training batch: a dancer facing the camera, the same dancer turning away, and a different competitor in a nearly identical black jacket. Which mistake should hurt most? Putting the two views of the same dancer far apart, or pulling the lookalike too close?
A loss function turns that question into training pressure. Identity classification asks the network to predict a training identity. Triplet loss compares an anchor, a same-identity positive and a different-identity negative. Angular-margin losses reshape a normalized classification space. Modern ReID systems often combine them because each notices a different kind of mistake.
The combination still does not turn an appearance embedding into proof of identity. At inference, you normally rank gallery crops that may contain people never seen during training. That is a different job from recognizing a fixed list of classes. The Person ReID guide explains the wider retrieval boundary.
Arrange the photographs on a table
Think of training as arranging photographs on a large table:
- Classification loss gives every training person a labeled tray and penalizes the model when a photo goes into the wrong tray.
- Triplet loss says that an anchor photo should sit nearer to another photo of the same person than to a photo of somebody else.
- Angular-margin loss asks for extra angular separation around the correct training class direction.
- Regularizers can shape the overall distribution so that the table does not collapse into a few crowded regions.
The labeled trays are a training device, not the final product. After training, a new person does not need a tray created in advance. Their crop is embedded and compared with other embeddings.
Identity loss: learn the labeled trays
The standard identity loss attaches a classifier to the embedding and applies softmax cross-entropy over the identities present in the training set. For an example with true class (y), the objective increases the logit for (y) relative to the other class logits.
Classification is useful because every training image is compared against many class weights at once. It can create clear decision regions and stable optimization. Label smoothing, used in the ReID Bag of Tricks baseline, slightly softens the one-hot target rather than demanding complete probability on one class.
There is an important limitation: test identities are normally unseen. A classifier can memorize training-specific shortcuts such as a camera background or recurring garment. Low training classification error therefore does not establish useful open-set retrieval.
The classifier is commonly removed at inference. The vector before it becomes the retrieval descriptor. Exactly which vector is used—before or after batch normalization, and before or after dimensional reduction—must be documented.
Triplet loss: make the difficult comparison count
A basic triplet contains:
- an anchor image (a);
- a positive image (p) of the same training identity;
- a negative image (n) of a different training identity.
With distance (d) and margin (m), a common form is:
max(0, d(a, p) - d(a, n) + m)
The loss is zero when the negative is sufficiently farther from the anchor than the positive. The difficulty lies in selecting informative triplets. Most random triplets soon become easy and produce no gradient.
In Defense of the Triplet Loss for Person Re-Identification popularized a practical batch-hard strategy for ReID. A batch samples (P) identities and (K) images per identity. For each anchor, training selects the farthest positive and nearest negative available inside that batch. The paper also studies a soft-margin form based on softplus, which avoids choosing a fixed hinge margin.
“Batch-hard” does not mean globally hardest. It only sees candidates in the current batch. Return to the black-jacket example: if the lookalike never enters the batch, it cannot become the hard negative. If a label is wrong, that mistake may become the strongest training signal and push the model in exactly the wrong direction.
Metric details matter too. Euclidean distance, squared Euclidean distance and cosine distance do not produce identical gradients. The Hermans paper reports a preference for non-squared Euclidean distance in its experiments. If an implementation uses squared distance, that is a legitimate implementation choice but should not be described as a verbatim reproduction.
ArcFace: add room around each class direction
ArcFace was introduced for face recognition. It normalizes features and classifier weights, then adds an angular margin to the target class before applying scaled softmax classification. This creates a geometrically interpretable pressure around class directions on a hypersphere.
Using ArcFace for Person ReID is a transfer of a published face-recognition objective. It can complement triplet learning, but it does not guarantee that every pair of different people will be separated by a fixed distance at inference. The margin modifies training logits. Real images can still overlap because of occlusion, similar clothing, domain shift or inadequate training coverage.
Scale and margin are hyperparameters, not universal constants. They interact with embedding dimension, batch construction, label quality and the other losses.
Put the objectives side by side
| Objective | Training unit | Pulls together | Pushes apart | Main caution |
|---|---|---|---|---|
| Cross-entropy ID loss | Image and class weights | Images toward their training class | Competing class logits | Training classes are not deployment identities |
| Batch-hard triplet | Anchor-positive-negative relation | Same-identity examples | Hard negatives in the current batch | Sensitive to sampling and label noise |
| ArcFace | Normalized image and class angle | Features toward target class direction | Adds angular pressure against other classes | Margin is not a pairwise inference guarantee |
| Alignment/uniformity regularization | Pairs and feature distribution | Positive or augmented views | Crowded regions of the hypersphere | Balance and sampling require validation |
The table describes mechanisms, not a ranking. More losses can create conflicting gradients and additional hyperparameters. A simpler, well-evaluated objective can be preferable to an elaborate unablated mixture.
Why teams combine objectives
Classification compares an image with persistent class weights. Triplet learning directly optimizes relative sample distances. Their signals can be complementary, but the representations preferred by the two objectives are not always identical.
The Bag of Tricks work introduced BNNeck as a practical separation. A batch-normalization layer sits between the shared feature and the classifier. The triplet loss is applied to one representation and the ID loss to the normalized representation. This is a published ReID design, not a generic property of all embedding models.
At evaluation time, the chosen descriptor must match the implementation and reported protocol. Switching from the pre-BN to post-BN feature can change neighbour rankings even when training is unchanged.
The broader geometry can also be described through alignment and uniformity. Wang and Isola formalize alignment as closeness of positive pairs and uniformity as spreading normalized features over the hypersphere. These concepts help explain why pulling positives together without preserving diversity may produce a poorly organized embedding space.
How to read the internal loss recipe
An internal DINO-ReID report combines an ArcFace-style classification objective with a soft batch-hard triplet objective. Its main schedule also contains a global-to-part alignment term and a confidence-entropy regularizer. A separate BAU-inspired section adds cross-view alignment, uniformity and a feature-bank term. ArcFace, batch-hard mining, soft-margin triplet learning, and alignment and uniformity are all grounded in prior literature.
The internal choices include the exact weights assigned to each objective, the use of squared distance, the progressive schedule that introduces objectives at different stages, the batch composition, and how these losses interact with its global and part descriptors. Those choices may be useful engineering contributions, but they require controlled ablation before a gain can be assigned to any one of them.
Calling the whole objective “new” would blur that boundary. A more accurate description is “an internally tuned combination and schedule of published loss families.”
Before you trust a loss comparison
For a reproducible loss comparison:
- Keep the backbone, embedding dimension and preprocessing fixed.
- Use identical identity-disjoint train, validation and test splits.
- Record the (P \times K) batch sampler and treatment of classes with few images.
- State the distance function, normalization point, margin, scale and loss weights.
- Verify labels and inspect the hardest positives and negatives.
- Tune on a calibration split, not the final test set.
- Report mAP, Rank-k and deployment-relevant false-candidate measures.
- Slice results by camera, occlusion, crop quality and domain.
- Run one-factor ablations before attributing a gain to a loss.
- Record which exact vector is indexed at inference.
Architecture remains a separate variable. See Person ReID model architectures before comparing an OSNet objective with a transformer objective as if only the loss had changed.
What a loss name cannot tell you
The cited papers do not prove that one loss mixture is universally optimal. Their conclusions are bounded by their datasets, samplers, backbones and evaluation protocols. A result produced with re-ranking is not directly comparable with a result produced by raw embedding distance.
Triplet loss does not guarantee that all same-person images are close. ArcFace does not enforce a permanent pairwise minimum distance between every different identity. Classification accuracy on training identities does not demonstrate retrieval quality for unseen people.
The internal report also does not isolate every loss contribution with controlled numerical ablations. Its private evaluation and named objectives do not establish the behavior of a served model unless checkpoint, preprocessing, indexed descriptor and evaluation protocol are matched. Loss names describe training pressure; they are not performance guarantees.