Bird's-Eye View: Many Cameras and Sensor Fusion
Modern self-driving cars fuse many cameras into one map seen from above. Mount four cameras on the car, see why flat-ground projection smears every car, lift pixels into 3D with depth as Lift-Splat-Shoot does, paint lidar points with camera classes, and train Lift-Splat-Shoot in Colab on four-camera recordings.
Softmaxima Simulator StudioWrite your car in Python, with as many files and trained networks as it needs, and watch it drive. In your browser, nothing to install.OpenIn plain words
Imagine a drone hovering above the car, drawing a map of everything around it. Modern cars build that map from several cameras (and lidar), but a camera picture has no depth, so the network must also learn how far away each thing is before it can put it on the map.
By the end of this topic you will be able to explain how several cameras are combined into one top-down map, and why depth is the key.
Start with: the demo Try it: four cameras, one map.
Why a bird's-eye view?
Planning happens on the ground: where are the lanes, where are the other road users, where can I drive? So modern stacks turn everything the sensors see into one bird's-eye-view (BEV) map around the car, usually 50–100 m across. Every camera, the lidar and the radar all contribute to the same grid. Detection, segmentation and prediction then all work on that grid, and the planner reads it directly. This idea, popular since 2020, is behind most camera-centred stacks today.
Try it: four cameras, one map
Front, left, rear and right cameras, merged into one map 40 m across. Start with flat-ground projection and look at the cars: long streaks pointing away from the car. Then lift each pixel with its depth. Then try the U-Net's own depth guesses, and finally lidar painted with camera classes.
Interactive: this part runs in your browser.
Going deeper
The sections marked Intermediate · Maths, Code or Advanced go deeper: the equations, the code and the finer details. They are worth it when you are ready, but you can follow the whole idea without them. To hide them, press those buttons next to Show at the top of the page; the Beginner explanations and Try it demos stay.
Flat-ground projection, and why it fails
Inverse perspective mapping (IPM) assumes every pixel lies on a flat road and projects it straight down, as our classic lane finder did in Part 2. Road markings land in the right place. But a point on a car's roof, 1.3 m up, is on the same camera ray as a road point much further away, so IPM puts it there:
# Flat-ground projection (IPM) assumes every pixel is on the road. Where does it put a point that is really above the road?
# A camera 1.4 m up sees a point at height z, d metres ahead, along the same ray as a road point at d * h / (h - z).
h = 1.4
print("true distance | height of the point | IPM puts it at")
for d in (10, 20):
for z in (0.0, 0.5, 1.0, 1.3):
print(f"{d:10} m | {z:13.1f} m | {d * h / (h - z):7.1f} m")
print("Points above the camera's height never hit the road at all: IPM cannot place them.")Lift, splat, shoot
Lift-Splat-Shoot (Philion and Fidler, 2020) fixes this by learning depth, without depth labels, from the BEV task itself:
- Lift: for every pixel of every camera, the network predicts a probability for each of D depth bins (say 2 m to 40 m), and a feature vector. Their outer product places a copy of the feature at every depth along the pixel's ray, weighted by how likely that depth is.
- Splat: every one of those 3D points falls in some BEV cell; add its feature into that cell. The camera geometry decides where, and it never changes, so the cell of every (camera, depth bin, pixel) is computed once.
- Shoot: a normal 2D CNN reads the BEV grid and predicts the map: road, markings, vehicles, pedestrians.
Trained end to end on the BEV labels, the network learns depth because putting features at the right depth is what makes the map right. Later work replaced splatting with attention: BEVFormer (Li et al., 2022) lets each BEV cell look up the image features it needs, and adds memory of past frames.
Code: record four cameras
The answer key for each frame is a 100 × 100 grid of 0.4 m cells around the car: nothing, road, lane marking, vehicle or pedestrian.
Interactive: this part runs in your browser.
Code: Lift-Splat-Shoot (Colab)
A small but complete version: shared camera encoder, depth distribution, the splat with one index_add_, and a BEV decoder. Expect roughly half an hour on a free Colab GPU for 400 frames; the exact time depends on the GPU you get.
# In Google Colab with a GPU. Upload multicam.npz from the recorder above.
# Lift-Splat-Shoot (Philion & Fidler, 2020), small: four camera images in, a bird's-eye-view map of road, markings,
# vehicles and pedestrians out. Each camera pixel predicts a depth distribution ("lift"), its features are spread
# along its ray into the grid ("splat"), and a small CNN reads the grid ("shoot").
from google.colab import files
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
d = np.load(list(files.upload())[0])
imgs, bev, rig = d["images"], d["bev"].astype(np.int64), d["rig"] # (n, 4, H, W, 3), (n, 100, 100), (4, 6)
n, NC, H, W, _ = imgs.shape
device = "cuda" if torch.cuda.is_available() else "cpu"
STRIDE, DB = 8, np.linspace(2, 40, 32) # features every 8 pixels; 32 depth bins, 2 to 40 m
fh, fw = H // STRIDE, W // STRIDE
CLASSES = ["nothing", "road", "lane marking", "vehicle", "pedestrian"]
# The geometry, worked out once: which bird's-eye-view cell each (camera, depth bin, feature pixel) falls into.
idx = np.full((NC, len(DB), fh, fw), -1, np.int64)
for c, (yaw, cx, cy, fov, h, pitch) in enumerate(rig):
f = (W / 2) / np.tan(np.radians(fov) / 2); p, yw = np.radians(pitch), np.radians(yaw)
v, u = np.meshgrid((np.arange(fh) + 0.5) * STRIDE, (np.arange(fw) + 0.5) * STRIDE, indexing="ij")
ry, rz = -(u - W / 2) / f, -(v - H / 2) / f
xr, zr = np.cos(p) + rz * np.sin(p), -np.sin(p) + rz * np.cos(p)
for k, dist in enumerate(DB):
t = dist / xr; lat = t * ry; z = h + t * zr # forward distance, sideways, height
X = cx + dist * np.cos(yw) - lat * np.sin(yw); Y = cy + dist * np.sin(yw) + lat * np.cos(yw)
r, q = np.floor((20 - X) / 0.4).astype(int), np.floor((20 - Y) / 0.4).astype(int)
ok = (r >= 0) & (r < 100) & (q >= 0) & (q < 100) & (z > -0.5) & (z < 3)
idx[c, k][ok] = (r * 100 + q)[ok]
IDX = torch.from_numpy(idx).to(device)
class LSS(nn.Module):
def __init__(s, C=48):
super().__init__()
def blk(i, o, st): return nn.Sequential(nn.Conv2d(i, o, 3, st, 1), nn.BatchNorm2d(o), nn.ReLU())
s.enc = nn.Sequential(blk(3, 32, 2), blk(32, 64, 2), blk(64, 96, 2), blk(96, 96, 1)) # 120 x 240 -> 15 x 30
s.depth = nn.Conv2d(96, len(DB), 1) # "lift": a depth distribution per pixel
s.feat = nn.Conv2d(96, C, 1)
s.bev = nn.Sequential(blk(C, 64, 1), blk(64, 64, 1), blk(64, 64, 1), nn.Conv2d(64, len(CLASSES), 1))
s.C = C
def forward(s, x): # x: (B, 4, 3, H, W)
B = x.shape[0]
z = s.enc(x.flatten(0, 1))
dep = s.depth(z).softmax(1) # (B*4, D, fh, fw)
fea = s.feat(z) # (B*4, C, fh, fw)
vol = (dep[:, :, None] * fea[:, None]).view(B, NC, len(DB), s.C, fh, fw) # every feature, at every depth
vol = vol.permute(0, 3, 1, 2, 4, 5).reshape(B, s.C, -1) # (B, C, cameras*depths*pixels)
flat = IDX.view(-1); ok = flat >= 0
grid = torch.zeros(B, s.C, 100 * 100, device=x.device)
grid.index_add_(2, flat[ok], vol[:, :, ok]) # "splat": add each feature into its cell
return s.bev(grid.view(B, s.C, 100, 100)) # "shoot": read the map
mean = torch.tensor(imgs[:50].reshape(-1, 3).mean(0) / 255, device=device).view(1, 1, 3, 1, 1).float()
std = torch.tensor(imgs[:50].reshape(-1, 3).std(0) / 255, device=device).view(1, 1, 3, 1, 1).float()
prep = lambda b: (torch.from_numpy(imgs[b]).to(device).permute(0, 1, 4, 2, 3).float() / 255 - mean) / std
cut = int(n * 0.85)
share = np.bincount(bev[:cut].ravel(), minlength=5) / bev[:cut].size
w = torch.tensor(1 / np.sqrt(share + 1e-4), device=device).float(); w /= w.mean()
net = LSS().to(device)
opt = torch.optim.AdamW(net.parameters(), lr=1e-3, weight_decay=1e-4)
for ep in range(25):
net.train(); perm = np.random.permutation(cut); tot = 0
for i in range(0, cut, 8):
b = np.sort(perm[i:i + 8])
loss = F.cross_entropy(net(prep(b)), torch.from_numpy(bev[b]).to(device), weight=w)
opt.zero_grad(); loss.backward(); opt.step(); tot += loss.item()
print(f"epoch {ep + 1}: loss {tot / (cut / 8):.3f}")
net.eval(); inter = np.zeros(5); union = np.zeros(5)
with torch.no_grad():
for i in range(cut, n, 8):
b = np.arange(i, min(n, i + 8)); pred = net(prep(b)).argmax(1).cpu().numpy(); true = bev[b]
for c in range(5):
inter[c] += ((pred == c) & (true == c)).sum(); union[c] += ((pred == c) | (true == c)).sum()
for c, name in enumerate(CLASSES):
print(f"{name:>13}: IoU {inter[c] / max(1, union[c]):.2f}")Expect good IoU for the road and markings, and lower for vehicles and especially pedestrians, which are small and only visible from their camera-facing side. Try more frames, or adding the lidar BEV grid from the previous topic as extra input channels: that is camera–lidar fusion in BEV (as in BEVFusion).
Fusion: early, late, and in between
- Late fusion: each sensor detects objects on its own; the results are merged (for example with a Kalman filter, as in Part 3). Simple and robust if one sensor fails, but each sensor's mistakes are made alone.
- Early fusion: raw data is combined first. PointPainting (Vora et al., 2020, the last demo option) colours each lidar point with the camera's class at that pixel, then runs a lidar detector on the painted points.
- BEV fusion: each sensor is turned into BEV features, the grids are stacked, and one network reads them. This is the most common design in research today.
Quiz
1. Why does flat-ground projection smear cars into long streaks?
2. In Lift-Splat-Shoot, what does "lift" produce for each pixel?
3. What does PointPainting add to each lidar point?
📚 Further reading
Trusted, mostly free sources: official documentation, well-known textbooks and courses. When you want to confirm or go deeper on anything here, start with these.
- Philion & Fidler (2020): Lift, Splat, Shoot ↗ many cameras into one bird's-eye view
- Li et al. (2022): BEVFormer ↗ bird's-eye view with attention and memory
- Vora et al. (2020): PointPainting: Sequential Fusion for 3D Object Detection ↗ painting lidar points with camera classes
- Caesar et al. (2020): nuScenes: A multimodal dataset for autonomous driving ↗ six cameras, lidar and radar with 3D labels