transfusion
Loss of the query-based TransFusionHead (LION): Hungarian-matched query targets and a dense center heatmap.
Classes:
-
TransFusionHeadLossβLoss of the
TransFusionHead(dense heatmap, matched classification, box, IoU rescore).
TransFusionHeadLoss [source] ΒΆ
TransFusionHeadLoss(
num_classes: int,
*,
point_cloud_range: Sequence[float],
voxel_size: Sequence[float],
feature_map_stride: int,
num_proposals: int = 200,
gaussian_overlap: float = 0.1,
min_radius: int = 2,
matcher_cls_cost: float = 0.15,
matcher_reg_cost: float = 0.25,
matcher_iou_cost: float = 0.25,
code_weights: Sequence[float] = (
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
0.0,
0.0,
),
cls_weight: float = 1.0,
loc_weight: float = 0.25,
heatmap_weight: float = 1.0,
iou_weight: float = 0.5,
focal_alpha: float = 0.25,
focal_gamma: float = 2.0,
)
Bases: Module
Loss of the TransFusionHead (dense heatmap, matched classification, box, IoU rescore).
Reference: TransFusion: Robust LiDAR-Camera Fusion for 3D Object Detection with Transformers (Bai et al., 2022).
The head predicts a dense per-class BEV heatmap plus a fixed set of object queries, each carrying a class logit vector and a box code. Four terms are summed:
- Heatmap: the ground-truth box centers are splatted onto a per-class BEV Gaussian map and the dense heatmap is supervised by the penalty-reduced center focal loss.
- Classification: every scene's queries are decoded to boxes and matched to the ground truth by a per-scene Hungarian assignment (cost: focal classification + normalized center \(L_1\) + 3D IoU). The per-query class logits are then trained by sigmoid focal loss over one-hot targets (background for unmatched queries), normalized by the positive count.
- Box regression: code-weighted \(L_1\) over the \(10\)-dim box code \((x, y, z + d_z / 2, \log d_x, \log d_y, \log d_z, \sin\theta, \cos\theta, v_x, v_y)\) at the matched queries.
- IoU rescore: an \(L_1\) term regressing the per-query
ioubranch toward \(2 \cdot \text{IoU}_{3D} - 1\) between each matched query's decoded box and its ground-truth box.
The loss holds no reference to the model: the grid geometry is rebuilt from the constructor params.
Parameters:
-
num_classes(int) βNumber of foreground classes (heatmap channels and query logits).
-
point_cloud_range(Sequence[float]) βRange \((x_\min, y_\min, z_\min, x_\max, y_\max, z_\max)\).
-
voxel_size(Sequence[float]) βVoxel size \((v_x, v_y, v_z)\).
-
feature_map_stride(int) βStride from the voxel grid to the BEV feature map.
-
num_proposals(int, default:200) βNumber of object queries per scene.
-
gaussian_overlap(float, default:0.1) βMin-overlap passed to the Gaussian-radius solver.
-
min_radius(int, default:2) βLower clamp on the integer splat radius.
-
matcher_cls_cost(float, default:0.15) βWeight of the focal classification term in the matching cost.
-
matcher_reg_cost(float, default:0.25) βWeight of the normalized center-\(L_1\) term in the matching cost.
-
matcher_iou_cost(float, default:0.25) βWeight of the 3D-IoU term in the matching cost.
-
code_weights(Sequence[float], default:(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0)) βPer-code regression weight, length \(10\); the last two (velocity) default to \(0\).
-
cls_weight(float, default:1.0) βMultiplier on the classification term.
-
loc_weight(float, default:0.25) βMultiplier on the box-regression term.
-
heatmap_weight(float, default:1.0) βMultiplier on the heatmap term.
-
iou_weight(float, default:0.5) βMultiplier on the IoU-rescore term.
-
focal_alpha(float, default:0.25) βFocal positive/negative balance (classification loss and matching cost).
-
focal_gamma(float, default:2.0) βFocal focusing exponent (classification loss and matching cost).
Methods:
-
forwardβCompute the TransFusion loss and its terms.
forward [source] ΒΆ
forward(
output: TransFusionHeadOutput, data: Dict[str, Any]
) -> Dict[str, Tensor]
Compute the TransFusion loss and its terms.
Parameters:
-
output(TransFusionHeadOutput) βThe head's raw output: per-query
center\((B, 2, Q)\),height\((B, 1, Q)\),dim\((B, 3, Q)\),rot\((B, 2, Q)\),vel\((B, 2, Q)\),iou\((B, 1, Q)\) andheatmap\((B, C, Q)\) class logits, plus the densedense_heatmap\((B, C, H, W)\). -
data(Dict[str, Any]) βPacked ground truth (
DataKeys.BOX\((K, 7)\) full-extent, or \((K, 9)\) with the velocity in the last two columns,DataKeys.LABEL\((K,)\) \(0\)-based,DataKeys.BATCH_BOX\((K,)\) per-box scene index).
Returns:
-
Dict[str, Tensor]βA dict with the scalar
lossand detachedheatmap_loss,cls_loss,box_loss,iou_loss.