Classical fusion tells the network which camera pixel belongs to each LiDAR point. Attention lets the network find it. In TransFusion's test, with all six cameras dead, a hard-matched fuser loses 23.8 mAP. The attention fuser loses 3.9.
Switch cameras off and watch the three fusers. Then we build, piece by piece, attention, the bird's-eye grid, BEVFormer, BEVFusion and TransFusion.
You need Lesson 18 (camera and LiDAR fusion by projection) and a dot product. We build the rest from zero.
Lesson 19 of the series Sensor Fusion: Classical to Modern. The numbers come from four papers of 2022: BEVFormer (Li et al.), two BEVFusions (Liu et al.; Liang et al.) and TransFusion (Bai et al.). The devices and toy numbers are our own.
Numbers from TransFusion, Table 5: nuScenes validation mAP with image features set to zero for the dead cameras. CC is point-wise concatenation and PA is the PointAugmenting fusion, both hard associations. Which camera dies is our choice; the paper drops cameras at random.
Chapter 0
Measure how far a small angle error throws a projected point, and see what a search window buys
A car fuses a camera and a LiDAR. The LiDAR sees a pedestrian 30 m ahead. A stored matrix says which camera pixel looks at that point, and the fuser glues that pixel's feature onto the point. Lesson 18 built this glue.
The matrix holds the calibration: the pose of the camera relative to the LiDAR. A pothole, summer heat or a loose bracket changes the real pose. The stored pose stays the same. Every point now lands on the wrong pixel, and the fuser has no way to notice.
How far off is it? Call the range to the object Z, in metres. Call the angle error of the camera Δθ, in radians.
e equals Z times delta-theta.
Turn the angle error Δθ from degrees into radians. Multiply it by the range Z. The product e is the miss, and it grows with range.
Half a degree is 0.5 × 0.01745 = 0.00873 rad. At Z = 50 m, e = 50 × 0.00873 = 0.44 m. That puts a pedestrian's LiDAR points on the road beside her.
The strip is a row of camera cells, 0.25 m wide at the object's range. The pedestrian is the bright cell. Add angle error and range.
An illustrative toy. Attention here searches 2 cells on each side of the projected spot and weights each cell by how well it matches the pedestrian's look.
Hard projection commits to one cell. Attention looks at a window around it and weights each cell by how well it matches. The window absorbs a small error. Push past 1.2° at 30 m and the pedestrian leaves the window: attention fails too.
So the lesson's idea is this. Stop telling the network where to fuse. Let a query, a vector that asks a question about one place, look at each sensor and weight the answers by how well they match. Three papers from 2022 built the modern stack on it.
| Method | Sensors | What asks, and what it looks at |
|---|---|---|
| BEVFormer | 6 cameras | one query per ground cell looks into the cameras |
| BEVFusion | cameras + LiDAR | both sensors draw one ground map; a convolution blends them |
| TransFusion | LiDAR + cameras | one query per object looks at LiDAR, then at the image |
Symptom: fused boxes slide sideways after someone touched a sensor mount, and the slide grows with range.
Measure: draw the LiDAR points on the image. Edges that miss by e = Z × Δθ point to an angle error.
Fix: recalibrate. Then use a fusion that searches a window (Chapters 3 and 5).
Chapter 1
Score each source against a question, turn the scores into trust, and watch trust move off a blinded camera
A ground cell wants to know: is there a car on me? A LiDAR patch and a camera patch can both answer. Attention decides how much to believe each one.
The question is a query vector. Each source carries a key, a vector that says what it can answer, and a value, the content it hands back. When the query comes from one place and the keys from another sensor, this is cross-attention. Call the query q and the key of source i ki. Each has d numbers.
s-i equals q dot k-i, divided by the square root of d.
Multiply q and k-i entry by entry and add. Divide by the square root of d. A big s-i means source i matches the question.
With made-up numbers: d = 4, so √d = 2. Say q · kL = 4.0 for LiDAR and q · kC = 3.2 for the camera. Then sL = 2.0 and sC = 1.6.
Scores can be any size. Trust must be positive and add up to one. The softmax turns scores into such weights. Call the weight of source i wi.
w-i equals e to the s-i, divided by the sum over j of e to the s-j.
Raise e to each score s-j. Add the results. Divide e to the s-i by that total. The weights w-i add up to one.
e2.0 = 7.389 and e1.6 = 4.953. The total is 12.342. So wL = 7.389 / 12.342 = 0.599 and wC = 0.401. LiDAR gets 60% of the trust.
The fused answer o blends the values vi by those weights:
o = wL vL + wC vC = 0.599 vL + 0.401 vC
The bars are the two softmax weights. They always add to 100%. Lower the camera's key quality, as glare would.
Illustrative scores: LiDAR fixed at 2.0, camera 1.6 times the key quality.
Glare washes out the camera patch, so its score falls to 0.2. Now e0.2 = 1.221, the total is 8.610, and wC = 0.142. LiDAR rises from 60% to 86%. No line of code checked for glare.
Symptom: training stalls, and every query puts almost all its weight on one source from the first step.
Measure: log the largest weight per query. Values near 1.0 everywhere mean the softmax has saturated.
Fix: divide by √d. With d = 256, raw dot products are 16 times too large.
Chapter 2
Give both sensors one map of the ground, and pay for every halving of the cell four times over
A camera gives a flat image in perspective. A LiDAR gives 3D points. You cannot add a pixel to a point, so both need one shared place to meet.
The bird's-eye view (BEV) is a top-down grid on the ground around the car, as a drone would see it. Each cell holds a feature vector that says what is there. BEVFormer uses 200 × 200 cells of 0.512 m, which covers ±51.2 m, with 256 numbers in each cell.
LiDAR enters the grid cheaply: each point already has its x and y, so it drops into its cell. The camera is the hard part. A pixel gives a direction but not a distance. Each method in this lesson gets the camera into the grid a different way.
Which patch of ground does a cell stand for? Call the cell's column x, the grid width W cells and the cell size s metres.
x-prime equals x minus W over two, times s.
Subtract half the grid width W from the column x, so the car's column becomes zero. Multiply by the cell size s. The result x-prime is metres from the car.
BEVFormer's grid has W = 200 and s = 0.512 m. Column 150 gives (150 − 100) × 0.512 = 25.6 m to the right. Column 0 gives −51.2 m, the left edge.
The dots are one LiDAR scan, dense near the car and sparse far away. Choose a cell size and a range.
An illustrative scan with a density of 2,000 / r² points per square metre. The cell counts are exact for the chosen grid.
Halve the cell and the count goes up four times: 0.256 m cells over ±51.2 m make 400 × 400 = 160,000 cells. Far cells starve. At 45 m most cells get no LiDAR point at all.
Symptom: two people walking side by side come out as one box.
Measure: compare the gap between objects with the cell size s.
Fix: smaller cells, at four times the memory and compute for each halving.
Chapter 3
Lift each ground cell to a pillar, project it into the cameras that see it, and sample around each landing pixel
BEVFormer uses six cameras and no LiDAR. It makes each grid cell a learned BEV query: 40,000 vectors of 256 numbers. Each query fills in its own cell.
A query knows its ground spot but not the height of what stands there. So it lifts itself to a pillar of 4 points at heights from −5 m to 3 m, and projects each into the cameras. Call the point's sideways offset in the camera frame xc, its depth zc, the focal length f and the image centre cu.
u equals f times x-c over z-c, plus c-u.
Divide the sideways offset x-c by the depth z-c. Multiply by the focal length f. Add the centre column c-u. The result u is the pixel column.
With made-up numbers: f = 1000 px, xc = 2 m, zc = 20 m, cu = 800 px. u = 1000 × 2 / 20 + 800 = 900. A 0.5° turn moves it by 1000 × 0.00873, about 9 px.
A pillar lands in one or two cameras, the hit views Vhit. Around each landing pixel P(p, i, j), deformable attention samples 4 spots at learned offsets in the camera's features Fi. The query Qp weights them and adds them.
F-p equals one over the number of hit views, times the double sum over hit views i and heights j of deform-attn of Q-p, P, and F-i.
For each camera i that sees the pillar and each height j, find the landing pixel P. Sample learned spots around it in F-i and blend them. Add every result. Divide by the number of hit views.
A query straight ahead hits 1 view: 1 × 4 heights × 4 samples = 16 sampled features per attention head. Dense attention over six feature maps of 32 × 88, the size BEVFusion uses, would score 16,896 keys.
Drag the warm query on the grid, or use the sliders. Lit strips are hit views; each holds the 4 pillar heights and their 4 samples.
Illustrative camera layout and sample offsets. The 4 heights and 4 samples are BEVFormer's.
Temporal self-attention adds last frame's grid, shifted by the car's own motion (ego-motion). Two frames show how far each object moved. On the nuScenes test set BEVFormer scores 56.9 NDS (nuScenes detection score, 0 to 100). DETR3D, the camera method before it, scored 47.9.
Symptom: boxes point the right way but sit at the wrong range, worse far away.
Measure: plot range error against range. Camera depth error grows with distance.
Fix: more temporal frames, depth supervision, or a LiDAR (Chapter 4).
Chapter 4
Draw a camera map and a LiDAR map on the same grid, stack them, and lose one without losing the scene
Now add the LiDAR back. Two teams published BEVFusion in May 2022: Liu et al. at MIT, and Liang et al. Both draw each sensor as its own map on the same grid cells, then fuse.
The cost hides in step 1. Call the number of cameras N, the feature map size H × W and the number of depth bins D.
M equals N times H times W times D.
Every feature pixel of every camera becomes D points, one per depth bin. Multiply N, H, W and D to count them. The pooling step adds all M points into their cells.
From the MIT paper: N = 6, H × W = 32 × 88, and D = (60 − 1) / 0.5 = 118 bins. M = 6 × 32 × 88 × 118 = 1,993,728, about 2 million points per frame.
Pooling 2 million points took more than 500 ms on an RTX 3090. The MIT team precomputed each point's cell and wrote one GPU thread per cell. The time fell to 12 ms, over 40 times faster.
Three objects: a near car, a far pedestrian and a mid car. Switch a sensor off. Then compare with points painted by camera pixels.
An illustrative toy with made-up evidence strengths and a detection threshold of 0.5. The paper's claim it mirrors: point-query fusers give no output when the LiDAR fails (Liang et al.).
Each branch alone covers the whole grid, so either can die. Liang et al. point out that fusers which use LiDAR points to query the image produce nothing when the LiDAR fails. Under training that simulates LiDAR failure, their BEVFusion beats earlier methods by 15.7 to 28.9 mAP.
Symptom: the detector misses its frame budget, and the camera branch takes most of the time.
Measure: time each stage. View transform above 100 ms means a slow pooling step.
Fix: precompute cell indices and pool with one thread per cell, as the MIT kernel does.
Chapter 5
Propose with LiDAR, refine with the image, and blend image features instead of picking one
A classical detector pairs each LiDAR box with one image region by projecting the box. That is a hard association. One bad projection makes one wrong pair, and nothing undoes it (Lesson 12).
TransFusion uses object queries: 200 vectors on nuScenes, each meant to become one object or nothing. They start at the 200 strongest peaks of a LiDAR heatmap, so each begins near a likely object.
The image adds the class and sharpens the box. Call the positions of the image features pj and their attention weights aj.
p-hat equals the sum over j of a-j times p-j.
Multiply each feature position p-j by its weight a-j. Add the products. A hard match takes the one feature nearest the projected spot instead.
From the device below: the object is at feature 7, and stage 1 proposes 7.02. A calibration offset of 3 moves the projected spot to 10.02. The hard match picks feature 10, an error of 3. The soft weights put 0.82 on feature 7, so p̂ = 7.23, an error of 0.23.
Press Decode: the query proposes on the LiDAR row, then refines on the image row. Then add calibration offset.
An illustrative toy, the same as the Code Lab below: image scores are 5 × appearance match minus 0.3 × distance from the projected spot. Offsets are in feature widths.
The paper tests the same idea at full scale. With LiDAR and cameras misaligned by 1 m, TransFusion loses 0.49 mAP. The two hard fusers lose 2.33 and 2.85. At night it gains 6.0 mAP over its LiDAR-only version, where the hard fusers gain 0.2 and 1.8.
Symptom: a fused detector is fine by day and no better than LiDAR alone at night.
Measure: split the validation set by day and night and compare with a LiDAR-only run.
Fix: let LiDAR propose and the image only refine, with soft weights.
Chapter 6
Drift the calibration and black out the camera, then compare fixed weights with softmax weights on three objects
Every method so far reduces to one move: a query weights each sensor by how well it matches right now. Here are three object queries on a grid. Each blends a LiDAR position and a camera position into one box.
With fixed weights, half and half, the blend trusts both sensors whatever happens. With softmax weights, the camera's score falls when its feature stops matching. That happens when the calibration drifts the camera's evidence away, or when a blackout flattens the camera feature.
The cross is the truth, where LiDAR (teal) also sits. The purple dot is the camera's evidence. The box is the blend; its bars are the two weights.
An illustrative toy. LiDAR score 2.0. Camera score 1.7 × (1 − blackout) × exp(−(drift / 0.6 m)²). A blackout also scatters the camera position by up to 1.5 m.
Drag the drift to 1.5 m. Fixed weights move every box by half of it, 0.75 m. Softmax weights drop the camera to 12%, so the boxes move about 0.18 m. Now black out the camera fully with no drift. Fixed weights scatter the boxes. Softmax weights run on LiDAR.
That is the hero's result in miniature. The two hard fusers welded the camera feature to each point with fixed trust. TransFusion re-weighted it.
Chapter 7
Drop whole sensors during training so a real failure looks familiar, and choose the stack around it
Soft weights only help if the network learned what a missing sensor looks like. A model trained with both sensors always on can lean so hard on the camera that it falls apart without it.
Modality dropout fixes this. On a fraction p of training examples, zero out one whole sensor, camera or LiDAR at random. The fused model must then learn to work on either one alone.
A tiny detector reads a camera feature and a LiDAR feature. Pick a dropout rate, press Train, and read the three test bars.
Real training on toy data: 400 examples, a logistic model, 400 steps of gradient descent. The camera feature is cleaner (noise 0.35) than the LiDAR feature (noise 0.6).
With p = 0, the model scores 95% with both sensors but 53% with the camera off, close to a coin toss. With p = 0.4, it holds 76% without the camera and loses 2.5 points with both on. A model trained on LiDAR alone reaches 80%, the ceiling for a dead camera.
| Choice | Pick this when | It costs |
|---|---|---|
| Cameras only | price decides, and a weaker night and range are acceptable | depth is a guess; leans on time and data |
| Cameras + LiDAR | one sensor fault must not blind the car | the LiDAR's price, and two branches to run |
| Finer cells | small, close objects matter most | 4 times the cells per halving |
| More past frames | velocity and brief occlusions matter | memory, and smear if ego-motion is wrong |
BEVFormer trains on 4 frames from the last 2 seconds and keeps one grid of history at test time. Every method here needs 3D box labels, which usually means a labelling car with a LiDAR, even for a camera-only product.
Symptom: one dead sensor in the field drops accuracy far below what the other sensor alone could give.
Measure: at test time, zero each sensor in turn and compare with a model trained on that sensor alone.
Fix: modality dropout, plus blur, darkening and point-dropping during training.
Chapter 8
Find six failure modes with two habits: switch sensors off, and split the metrics
Robust is not the same as correct. Each failure below has a symptom you can see and a test you can run. Almost every test is one of two habits. Ablate: switch one sensor off at test time and watch the accuracy change. Stratify: split the metrics by range, light, weather or city.
| Failure | Symptom | Test | Fix |
|---|---|---|---|
| Modality collapse | camera off costs nothing | ablate; mean weight per sensor under 5% | modality dropout, warm up each branch |
| Camera depth | right bearing, wrong range | range error against range | LiDAR, more frames, depth labels |
| Ego-motion | doubled or smeared static objects | overlay last grid on this one | better odometry, fewer frames |
| Large miscalibration | accuracy falls off a cliff | inject offsets, sweep them | recalibrate, wider sampling |
| Domain shift | fails at night, in rain, in a new city | stratify by condition and place | collect and up-weight those data |
| Latency | boxes arrive after the frame | time each stage | fast pooling, coarser grid |
Take the ego-motion row. Temporal fusion rotates last frame's grid by the car's measured turn. If the odometry reads the turn wrong by an angle, every static object in the old grid moves by its range times that angle. This is e = Z × Δθ from Chapter 0, now in time instead of between sensors.
The grey poles are this frame. The yellow rings are last frame's poles after the warp. Add a yaw error to the odometry.
Illustrative pole layout. The ghost offsets are exact: range times the yaw error in radians.
A 1° error splits a pole at 40 m into two, 0.70 m apart. At 10 m the split is 0.17 m and hard to see. So check the far poles first: a static scene must line up exactly after the warp.
Chapter 9
Keep the terms, the numbers, the checks and the code in one place
Classical fusion told the network where to fuse with a calibration matrix. Transformer fusion lets a query find it, with softmax weights that move off a sensor that stops matching.
| Term | Meaning | Number to remember |
|---|---|---|
| Projection miss | range times angle error | 0.5° at 50 m: 0.44 m |
| Cross-attention | a query scores another sensor's keys; softmax gives trust | scores 2.0 and 1.6: 60% and 40% |
| BEV grid | a top-down map both sensors share | 200 × 200 × 256, cells 0.512 m |
| BEVFormer | grid queries sample around projected pillars, plus last frame | 4 heights, 4 samples; 56.9 NDS |
| BEVFusion | camera and LiDAR maps on one grid, stacked | 2 million points pooled in 12 ms |
| TransFusion | LiDAR proposes, the image refines softly | 6 cameras dead: 61.7 mAP, against 39.5 |
| Modality dropout | zero a whole sensor on some training examples | toy: camera-off 53% to 76% |
| Ego-motion error | a misread turn splits static objects | 1° at 40 m: 0.70 m |
pythonimport numpy as np def softmax(s): e = np.exp(s - s.max()) # subtract the max so exp never overflows return e / e.sum() def cross_modal_attention(q, K, V): # q: (d,) one query. K, V: (n, d) keys and values, LiDAR rows and camera rows stacked s = K @ q / np.sqrt(q.size) # one score per source w = softmax(s) # trust: positive, adds to one, across both sensors return w @ V, w # the fused answer and the weights def bev_x(col, W=200, s=0.512): # a grid column to metres right of the car return (col - W / 2) * s def soft_position(a, p): # TransFusion's refine step, in one line return float(a @ p) softmax(np.array([2.0, 1.6])) # [0.599, 0.401] both healthy softmax(np.array([2.0, 0.2])) # [0.858, 0.142] glare on the camera bev_x(150) # 25.6 m
Now press Present or Teach and explain from memory: the projection miss, the softmax weights, the grid, and the three methods. Then go back to the hero, kill all six cameras, and say why the green bar barely moves.