Sub topic 9
Appearance Embeddings and Re-Identification
This chapter assumes that you understand object detections, bounding boxes, IoU matching, and basic track prediction. The goal is to keep an object's identity when its position alone is not enough to match it.
Why appearance helps
An appearance embedding is a numeric vector that summarizes how an object looks. A neural network creates the vector from an image crop, such as a detected person's bounding box. Two crops of the same person should produce nearby vectors, even when the person moves or changes position.
Re-identification, often called ReID, is the process of recognizing that an object seen now is the same object that appeared earlier. A tracker can use ReID when a person disappears behind another person, crosses a camera view, or returns after a long detection gap.
An embedding does not store an identity label by itself. The tracker compares the new vector with vectors saved for existing tracks. A common comparison is cosine distance:
- Cosine similarity near 1 means the vectors point in similar directions.
- Cosine distance is
1 - cosine similarity. - A small distance suggests a possible identity match.
The embedding model should be trained for the target domain. A model trained on pedestrians may perform poorly on vehicles, animals, or infrared video.
Building an appearance cost
For each detection, crop the image and pass the crop through the ReID model. Store the resulting vector with the track. Before matching, normalize every vector to length 1. Then cosine similarity becomes a dot product.
import numpy as np
def normalize_rows(vectors):
vectors = np.asarray(vectors, dtype=float)
lengths = np.linalg.norm(vectors, axis=1, keepdims=True)
return vectors / np.maximum(lengths, 1e-12)
def cosine_distance_matrix(track_features, detection_features):
tracks = normalize_rows(track_features)
detections = normalize_rows(detection_features)
similarity = tracks @ detections.T
return 1.0 - similarity
track_features = np.array([
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
])
detection_features = np.array([
[0.9, 0.1, 0.0],
[0.1, 0.8, 0.1],
])
print(cosine_distance_matrix(track_features, detection_features))The resulting matrix has one row per track and one column per detection. The tracker can give low-cost pairs to the Hungarian algorithm. It should also reject pairs whose appearance distance exceeds a chosen threshold.
Combining motion and appearance
Appearance is strongest when several nearby objects look different. Motion is stronger when objects have distinctive positions and predictable movement. DeepSORT combines both signals:
- Predict each track's new position with a motion model.
- Reject detections that are physically implausible for that track. This is called gating.
- Compare the remaining pairs using appearance distance.
- Solve the assignment problem.
- Update the matched track's appearance history.
A combined cost can be written as:
cost = α × motion_cost + (1 - α) × appearance_cost
The weight α controls the trade-off. Increase it when appearance is unreliable, such as in poor lighting. Decrease it when objects move unpredictably or frequently overlap.
| Strategy | Strength | Common weakness |
|---|---|---|
| IoU and motion | Fast and simple | Fails after occlusion or crossing |
| Appearance only | Handles position changes | Can confuse similar-looking objects |
| Motion plus appearance | Uses complementary evidence | Requires tuning and a ReID model |
Track appearance history
A single embedding can be noisy because a crop may be blurred, partially hidden, or poorly framed. Tracks often keep several recent embeddings or an exponential moving average. Before adding a vector to the history, reject detections with very small boxes or low detector confidence.
Appearance matching can preserve an identity, but it cannot prove identity. Use conservative thresholds and let an uncertain detection remain unmatched rather than forcing an ID switch.
Exercise
Why should a tracker reject an appearance match even when its embedding distance is small?
Show answer
The pair may violate the motion gate, come from a poor crop, or create an implausible assignment with another detection. Appearance is evidence, not proof.