matching
Set-prediction matching between predictions and ground-truth objects.
Functions:
-
hungarian_matchβOne-to-one assignment of predictions to targets minimizing the total cost (Hungarian algorithm).
-
hungarian_match_batchedβOne-to-one assignment of every scene's predictions to its targets, with a single device transfer.
hungarian_match [source] ΒΆ
One-to-one assignment of predictions to targets minimizing the total cost (Hungarian algorithm).
The matcher of the set-prediction detectors (3DETR, TransFusion): every target is matched to exactly one prediction and the sum of the matched costs is minimal. The cost matrix is built by the caller (e.g. a weighted sum of a classification, a center-distance and an IoU term) and must be finite.
Parameters:
-
cost(Tensor) βPairwise cost of every prediction / target pair, shape \((Q, M)\).
Returns:
-
TensorβA tuple
(pred_indices, target_indices)of long tensors oncost.device, each of length -
Tensorβ\(\min(Q, M)\), such that
pred_indices[i]is matched totarget_indices[i]; both are empty when -
Tuple[Tensor, Tensor]βeither side is.
Shape
- cost: \((Q, M)\)
- pred_indices: \((\min(Q, M),)\)
- target_indices: \((\min(Q, M),)\)
hungarian_match_batched [source] ΒΆ
One-to-one assignment of every scene's predictions to its targets, with a single device transfer.
The batched form of hungarian_match for a padded cost tensor: scene \(i\) uses the first num_targets[i] target columns of cost[i]. The whole tensor is moved to the CPU once and every scene is solved there, so a loop over scenes (and decoder layers, when they are stacked along the batch dimension) costs one synchronization instead of one per scene.
Parameters:
-
cost(Tensor) βPairwise costs, shape \((N, Q, M_\max)\); the columns beyond a scene's target count are ignored and may hold anything finite or not.
-
num_targets(Sequence[int]) βNumber of valid target columns of each scene, length \(N\).
Returns:
-
TensorβThe matched target index of every prediction, shape \((N, Q)\) long on
cost.device, \(-1\) where the -
Tensorβprediction is unmatched.
Shape
- cost: \((N, Q, M_\max)\)
- output: \((N, Q)\)