KnowML

3D, Spatial AI & Autonomous Driving

Follow one traffic cone through a self-driving car's cameras, LiDAR and radar, from the pixel it lights up to the braking decision. You'll learn the camera geometry and the learned representations that turn partial views into one 3D picture.

⏱ 26 min readAssumes: CNNs & detection basics (05), attention & transformers (08)
Start reading

Picture a car driving down a street with an orange traffic cone sitting in its lane, ten metres ahead and a metre to the right of where the front camera points. Now the car has to decide whether that cone is something to brake for, steer around or ignore, and maybe the answer changes with its position. To decide, it needs to know where the cone is in three dimensions, roughly how big it is, and whether it's moving. This chapter follows that one cone through the car's sensors and software, from the pixel it lights up to the braking decision, and on the way it covers the geometry and the learned models that make up a modern self-driving stack.

The car has three kinds of sensors for this job: cameras, LiDAR (a laser range finder) and radar. Each one tells us something about the cone and hides something else, so no single sensor gives a trustworthy answer. The central problem of the field is combining them. We take pixels from several cameras, laser points and radar returns, express all of them in one shared 3D coordinate system, and run detection, tracking, forecasting and planning on that shared picture instead of building a separate pipeline for every sensor. Camera geometry is the mathematics that makes the sharing possible. Learned models, which we'll meet by name later, do the combining.

We'll go in the order the cone's information travels. First we see what each sensor can and can't say about the cone, then the geometry that turns a 3D point into a pixel and back, then the stack itself, piece by piece: where the car is, what's around it, where everything is going, and what to do about it. After that comes the design question that shapes the whole field: why the stack fuses features into a top-down picture before detecting anything, and why almost every deployed system keeps its stages separate instead of training one network from pixels to steering. The chapter closes with the failures that show up in production.

We assume you know the basics of convolutional networks and object detection from chapter 05, and attention from chapter 08. If you want one sentence for an interview, it's this: autonomous driving is a real-time 3D perception problem wearing a robotics costume, and its central engineering tension is fusing complementary, imperfect sensors into one consistent world model fast enough, and reliably enough, to plan around safely.

01Three sensors, one traffic cone

Start with the camera, since it's the cheapest and the most familiar. A camera image is a grid of pixels, and each pixel records the light that arrived along one direction. That makes the image a 2D projection of the world, and by the time light reaches the sensor, depth is already gone. Our cone and a taller object far behind it could land on exactly the same pixel, and a single camera has no way to tell them apart. To get distance back, it needs extra assumptions (a cone is probably about this tall) or a second view to triangulate against.

LiDAR fixes this directly. The name stands for light detection and ranging: the unit fires short laser pulses, times how long each takes to bounce back, and converts that time into a distance. A rotating unit sweeps in a circle and returns a point cloud, a set of 3D points, one for each place a pulse hit something. For our cone at ten metres, that means a precise distance but only a handful of points on it, because the cloud is dense up close and sparse at range. It also says nothing about the cone's color or fine texture, and it's the most expensive sensor in the stack.

Radar sends out radio waves instead of light, and its advantage is speed. A moving object shifts the frequency of the wave it reflects, an effect called the Doppler shift, so radar measures velocity directly and immediately. Cameras and LiDAR can only infer velocity by comparing several frames. The price is spatial resolution: radar is coarse enough that it often can't tell an object's exact shape, or whether two nearby objects are one or two.

So for our cone, the camera knows what it looks like but not how far away it is, LiDAR knows how far but not what it is, and radar knows whether it's moving but little else. Two questions organize everything that follows. First, how to turn what one sensor sees into a 3D fact about the world, and that's camera geometry, stereo depth and LiDAR point-cloud processing. Second, how to combine facts from sensors that measure different things at different rates and sometimes disagree, and that's sensor fusion, bird's-eye-view representations and occupancy networks. Get the first right and you have accurate individual readings that still don't agree with each other. Get the second right and the disagreement turns from a source of confusion into a source of robustness, because each sensor covers the others' blind spots.

Let's make the camera's loss of depth concrete with the cone. Below, the code places a point on the cone 1 m to the right of the camera's axis and 0.5 m below it, then moves it to three different distances and prints the pixel it lands on. Its project function is the whole camera model: divide the sideways and vertical offsets by the distance Z, scale by the focal length f (a lens property, measured here in pixels), and add the image center (cx, cy) so that a point straight ahead lands in the middle of the image.

Try it Project a 3D point onto a camera image
f = 800.0                                    # focal length in pixels
cx, cy = 320.0, 240.0                        # image center

def project(X, Y, Z):
    return f * X / Z + cx, f * Y / Z + cy    # x = f X / Z

for Z in (5, 10, 20):
    u, v = project(1.0, 0.5, Z)
    print(f"{Z:>2} m away -> pixel ({u:.0f}, {v:.0f})")
The same point, 1 m right and 0.5 m down, lands at pixel (480, 320) at 5 m, (400, 280) at 10 m and (360, 260) at 20 m. Moving it further away pulls it toward the image center at (320, 240). Going the other way, from a pixel back to a 3D position, needs the distance, and one image doesn't contain it.

Look at what moved and what didn't. The point is always 1 m right and 0.5 m down, yet its pixel slides toward the image center as it recedes, from (480, 320) at 5 m to (360, 260) at 20 m. That division by Z is why far things look small. It also shows the one-way nature of the projection: going forward, a distance gives a pixel, but going backward, a pixel fits every distance along a ray, so one image can't give the cone's position, and you've probably guessed that a second view is the way out. Recovering that distance is what the rest of the geometry is for, and it starts with writing the projection down properly for a real car, which has many cameras that aren't all pointing the same way.

02The math: from a 3D point to a pixel

Intrinsics and extrinsics

The little project function assumed the cone's position was given in the camera's own coordinate frame, with the origin at the lens and the Z axis pointing straight out. A coordinate frame is just a choice of origin and axes for writing positions down. A real car has six to eight cameras, each mounted at a different spot and angle, plus a LiDAR and radars, and each sensor naturally reports the cone in its own frame. To combine them we need a conversion between frames, and then the projection itself, and these are two separate jobs.

The first job belongs to the extrinsic transform, a rotation and a translation that describe where a camera sits and which way it points relative to the vehicle. It converts a point from world (or vehicle) coordinates into that camera's frame. And the second job belongs to the intrinsic matrix , which holds properties fixed by the lens and sensor: the focal length, and the principal point, the pixel where the camera's axis meets the image. It maps a point already in the camera's frame down to a 2D pixel, exactly what project did with f, cx and cy. A single camera needs only its own pair. A multi-camera rig needs every camera's extrinsics measured against one shared reference frame, typically the vehicle's own center. That shared frame is what lets us place features from six differently mounted cameras correctly relative to each other, instead of keeping six disconnected pixel grids.

Chaining the two jobs gives the camera projection equation:

  • X, Y, Z a point's coordinates in the world (or vehicle) frame.
  • R, t the camera's extrinsics: a rotation and translation converting that world-frame point into the camera's own coordinate frame.
  • K the camera's intrinsic matrix (focal length and principal point), projecting the camera-frame 3D point down onto the 2D image plane.
  • u, v the resulting pixel coordinates, up to the scale factor . That scale factor is the point's depth, and the projection alone throws it away. Hence depth estimation being a separate, hard problem.

Our earlier code is the special case where the camera sits at the vehicle's origin and looks straight ahead, so and do nothing. Here the scale factor is the Z we divided by, and the equation makes the loss of depth precise: given and the matrices, every value of is consistent with the pixel. If one camera can't recover , can two?

Epipolar geometry, stereo and depth

Take two cameras with a known, fixed offset between them, and look at the same real-world point, our cone. It appears in both images, and we'd like to find it in the second image given where it is in the first. Searching the whole second image would be slow. Epipolar geometry says we don't need to: once we know the two cameras' relative pose, a point's location in the first image constrains its possible location in the second to a single line, the epipolar line. For two calibrated cameras viewing the same point, that constraint is:

  • x, x' the same real-world point's pixel coordinates in the first and second camera respectively.
  • F the fundamental matrix, encoding the two cameras' relative geometry: their relative plus intrinsics.
  • Given and , this equation defines a single line in the second image, the epipolar line, that is guaranteed to lie on. This is why stereo matching needs only a 1D search along a line and not a full 2D image search.

That collapses stereo matching from a 2D search into a 1D one. That's the difference between computing it on every frame in real time and not computing it at all. Once a match is found, depth falls out of the geometry directly. A far point shifts only slightly between the two images, and a near point shifts a lot. That shift is called the disparity, and for a fixed baseline (the distance between the cameras) disparity is inversely proportional to depth. So the projection equation told us one camera loses depth, and the epipolar constraint tells us how a second camera gets it back. How does all of this fit into a working driving system?

03The stack, piece by piece

A modern autonomous driving stack is a pipeline, much like the robotics pipeline in chapter 21, but with 3D geometry doing more of the early work. Raw sensors feed geometric and learned perception, and the perception output gets fused into one shared representation. That representation feeds prediction, prediction feeds planning, and planning's output becomes control commands for the steering and pedals. The diagram shows the flow, and the sections below take the stages in the order the cone's information passes through them.

Sensors → shared 3D representation → plan — one pipeline, several sensor streams
sensors Cameras (×N) LiDAR Radar Fusion: BEV grid / occupancy volume one shared 3D frame Detection & tracking Trajectory prediction Motion planning Control (21's PID/MPC)
Three sensor streams, running at different rates and with different failure modes, get lifted into one shared bird's-eye-view or occupancy representation before anything downstream runs. Detection and tracking, prediction, and planning are almost always kept as separate stages, and section 04 explains why.

SLAM and visual-inertial odometry

Before the car can say where the cone is in the world, it has to know where it is itself. Simultaneous localization and mapping (SLAM) is a genuine chicken-and-egg problem. To know where you are, it helps to already have a map, and to build a map, it helps to already know where you are. SLAM solves both at once, jointly estimating the camera's trajectory and a map of tracked landmarks (distinctive points it can recognize again), and refining both as new observations arrive.

Visual-inertial SLAM tightly couples camera tracking with an IMU, an inertial measurement unit that reports acceleration and angular velocity. ORB-SLAM3 is the well-known open-source reference implementation. The two sensors cover for each other: the IMU fills in fast, high-frequency motion between camera frames, and it stays useful through the camera's worst moments: motion blur, brief occlusion, a tunnel, and the camera in turn corrects the IMU's slow drift whenever it can see stable landmarks again. With the car's own motion known, we can turn to the cone.

3D object detection from LiDAR and from cameras

Detecting the cone in a LiDAR point cloud means solving an awkward data-structure problem first. A point cloud is sparse, unordered, and wildly uneven in density, while a standard CNN is built for dense, regular pixel grids and can't consume it directly. PointPillars answers this in three moves. It discretizes the ground plane into a grid of vertical columns, the "pillars". It runs a small shared network over the points inside each pillar to produce one feature vector per pillar. Then it arranges those vectors into a 2D pseudo-image that an entirely ordinary 2D CNN detector can process. That turns an irregular 3D problem into a regular 2D one, with no 3D convolutions at all, so it runs fast enough for a moving vehicle.

Camera-based 3D detection has the harder job, because it must estimate depth that was never directly measured. It can do that per camera, through monocular (single-camera) depth estimation (generally less accurate), or jointly across camera views, the way the bird's-eye-view methods below do. That accuracy gap is a large part of why multi-camera approaches displaced monocular 3D detection as the camera-only default. So what exactly do those methods build?

Bird's-eye-view representations

Bird's-eye-view (BEV) is a top-down 2D grid over the ground plane around the vehicle, with the car in the middle. Each cell of the grid covers a small patch of road, and our cone would occupy a cell ten metres up and one to the right.

Why a top-down grid, when we could keep full 3D coordinates?

Mostly because it's the natural shared frame for driving. Planning a route and reasoning about lanes are inherently top-down problems, and nobody plans a maneuver by thinking in raw camera-pixel coordinates. If every sensor's features land in the same top-down grid, then the planner, the tracker and the predictor all work in the frame they need.

BEVFormer builds this grid directly with attention (chapter 08). It starts with a fixed grid of learned BEV queries, one per top-down cell, and uses two attention mechanisms. Spatial cross-attention lets each cell pull in the relevant image features from whichever camera views see that patch of ground. Temporal self-attention fuses the current BEV grid with the previous timestep's grid. That temporal half matters more than it first looks: it noticeably helps estimate a moving object's velocity, and it recovers objects that were briefly occluded a frame ago, because the model isn't restarting perception from zero every frame.

Occupancy networks: past the bounding box

So far we've assumed the cone is something a detector can name and draw a box around. A bounding box is a rectangular 3D box that a detector draws around an object, and it assumes the world is made of a fixed, known set of object categories with roughly box-shaped extents.

What happens to a fallen ladder, or a spilled load of cargo?

A detector's training set never named it, so the detector may not register it at all. An occupancy network sidesteps the problem. For every cell in a grid around the vehicle (in 3D, a cell is called a voxel, a small cube of space), it predicts whether the cell is occupied and, if so, by roughly what kind of thing. That turns "list the objects" into "describe free space directly", which degrades far more gracefully on anything unusual.

TPVFormer makes this tractable with a trick. Instead of one dense 3D voxel grid, it represents the volume as three orthogonal 2D planes: the top-down view plus the two perpendicular side views. Combining the three planes recovers the full 3D structure at meaningfully lower cost than predicting every voxel directly.

Sensor fusion: camera, LiDAR and radar together

We now have good ways to use cameras and LiDAR separately, and radar still sits to the side. Maybe you're wondering why it's in the stack at all, given its coarse resolution, and we'll get to that. Fusion can happen at three points in the pipeline, and where you put it is the whole design decision. In early fusion we combine near-raw sensor data before much processing. It's the hardest to get right, but no information is thrown away before the combination. In late fusion we run separate full detectors per sensor and combine only their final outputs. It's the simplest to build and debug, but each detector may already have discarded a cue that is only visible when signals are considered jointly. In between sits fusing intermediate features, and BEVFormer-style camera fusion, extended to also ingest LiDAR or radar features into the same shared grid, is the currently favored middle ground.

Why these three sensors specifically?

Camera, LiDAR and radar are a deliberately complementary trio, and "more sensors are better" doesn't describe them. Camera data supplies rich semantic detail that the other two structurally can't: what is this, what color is it, what does the sign say. LiDAR supplies precise geometry that monocular camera depth estimation can't match. Radar supplies direct, instantaneous velocity, and it keeps working through fog, rain and glare that badly degrade cameras and, to a lesser extent, LiDAR. Each one's weakness is another's strength. That's why the trio works, and why fusion has to be done carefully, as we'll see at the end of the chapter.

Scene graphs and spatial reasoning

Once the fused representation gives us a list of tracked things, the planner needs to ask questions about how they relate. A scene graph represents the world as nodes (vehicles, pedestrians, lanes, traffic signals) connected by labeled relational edges: "in front of," "yielding to," "occupies this lane." That's richer than a flat, unstructured list of detections, and it makes higher-level spatial queries answerable directly. "Which vehicles are relevant to my current lane change" becomes a graph query over relationships, and the car doesn't have to re-derive it from raw geometry every time it's asked.

Trajectory prediction and motion planning

Our cone doesn't move, but the pedestrian next to it might. Trajectory prediction takes each tracked agent's recent motion history plus map context (lanes, right-of-way, traffic controls) and forecasts several plausible future paths. Tracking here means keeping the same identity on an object from frame to frame, so that "recent motion history" exists at all.

Why predict several futures instead of one?

Because "what will that pedestrian do" is inherently multimodal, meaning there are several distinct likely outcomes. They might cross or they might not, and a model that averages both possibilities into a single path is wrong in exactly the way chapter 21's behavioral-cloning discussion describes: the average of "step out" and "stay put" is a pedestrian standing half in the road, which nobody will do. MotionNet illustrates one clean way to structure the forecast. It takes BEV maps as input and predicts, per grid cell, both a category and a short-horizon motion vector, so detection and near-term prediction live inside one shared BEV representation instead of two disconnected models.

Motion planning then takes the ego vehicle's goal (the ego vehicle is our own car, as opposed to the other agents) plus every predicted agent trajectory, and searches for a path that's safe, comfortable and legal. Safe means it doesn't intersect anyone else's likely future path. Comfortable means bounded acceleration and jerk, where jerk is how quickly the acceleration changes. Legal means it obeys lane and traffic-control constraints. Conceptually this is the same constrained trajectory-optimization idea as model predictive control (MPC) in chapter 21. Scope is what differs: one long route instead of one short re-planned step, re-run continuously as new predictions arrive. That winning trajectory then goes to a classical controller to turn it into steering and braking.

Closed-loop evaluation, and simulating from real drives

How do we know the planner is any good? The same open-loop versus closed-loop distinction from chapter 21 applies here, with higher stakes. Open-loop evaluation replays a fixed recorded log and checks whether the planner's outputs match what happened. It's cheap, fast and fully reproducible, and it's also blind to compounding error, because the ego vehicle's hypothetical actions never change what the scenario does next. A bad early decision never gets the chance to cascade. Closed-loop evaluation lets the planner's decisions affect the simulated scenario going forward, and it's the only way to catch failures that appear after the car has already made one small mistake.

Closed-loop needs a simulator that looks like the real world, and this is where NeRF and Gaussian splatting (chapter 06 covers how they work as general 3D scene representations) get their driving-specific use: reconstruction for simulation. Take a real recorded driving log, reconstruct the scene the car drove through as a NeRF or a set of Gaussians, then re-render it from camera viewpoints the car never took, or with other actors inserted or removed. That gets much closer to testing against reality than a purely synthetic simulator, because the environment was reconstructed from a real drive and not hand-modeled. World models (chapter 22) increasingly play a similar role as fast, learned simulators: instead of testing planning only against a fixed replay log or a hand-built physics simulator, you roll candidate plans forward inside a learned model of how the scene evolves, cheaply and safely, before anything touches the real world.

End-to-end driving

Every stage above has its own inputs, outputs and losses. End-to-end driving asks whether that separation is necessary, and trains one network to map sensor inputs directly to a planned trajectory, or even to control outputs. It optimizes jointly against one end-task loss instead of stage-by-stage intermediate losses. In principle that lets it discover something the modular pipeline structurally can't see: that a slightly different detection threshold would have produced a much better downstream plan. Whether that promise outweighs what it costs is the question the next section takes up.

04Why BEV and occupancy, and why modular over end-to-end

It helps to see the stack as the end of a short history. Through the 2000s and early 2010s, depth came from structure-from-motion and classical stereo, tracking from SIFT-style features and Kalman filters, and planning from explicit rules. All of it was rigorous and interpretable, and each piece degraded in glare, rain and unanticipated object shapes. Then learning took over the pieces. PointPillars (2018) made LiDAR detection fast and learnable, ORB-SLAM3 (2020) fused camera and IMU in one optimization, and BEVFormer (2022) lifted several camera views into one bird's-eye-view grid with learned cross-attention, so features are fused first and detection happens once. Since 2023, occupancy networks have predicted free space and semantics per voxel, so odd obstacles still show up as occupied, and whether the stack should be modular-but-learned or end-to-end is still unsettled. Two of those choices deserve a closer look.

Start with where fusion happens. Fusing per-camera detections after the fact is the obvious first design, and it's also a worse one. Each camera's detector has already thrown information away by the time it commits to a final box. Suppose two cameras jointly saw a partially occluded object, but neither alone saw enough to be confident. Late fusion never gets to combine their partial evidence, because it was discarded before fusion ran. Lifting features into a shared BEV grid before detecting anything keeps that partial evidence alive long enough to combine, and that's why BEVFormer-style architectures displaced "detect per camera, then merge boxes" as the default.

Occupancy networks push the same logic further. A bounding-box vocabulary is a closed set of categories decided at training time, and the real world reliably produces obstacles outside that set. Predicting occupancy directly, without committing to "this is definitely a car, definitely this size," degrades gracefully on exactly the long-tail shapes a fixed category list can't name.

The modular-versus-end-to-end question is harder, because it doesn't have a settled answer, and treating it as settled is a tell that someone hasn't thought about the actual tradeoff. A modular pipeline keeps perception, prediction and planning as separate stages with separate losses, so every stage is independently testable. If the car braked unnecessarily, you can inspect whether perception mis-detected something, prediction mis-forecast a trajectory, or planning made a bad call given otherwise-correct inputs, and each stage validates against its own held-out data. An end-to-end network optimized on one final task loss can in principle find a jointly better solution across all three at once, a slightly different detection behavior that happens to produce much better downstream plans. But that joint optimum arrives with no clean way to say why the network did what it did, and that's precisely the property regulators, safety cases and post-incident investigations need.

The tension is global optimality against stage-by-stage interpretability. End-to-end can reach a better solution, and modular can tell you why it reached the one it did. For a safety-critical system, the second property isn't a nice-to-have you trade away for accuracy. That single tension is why modular pipelines remain the deployed standard, while end-to-end stays a very active, not-yet-dominant research direction. Choosing a design is one thing. Knowing how each choice fails once it's on the road is the next.

05Complexity, failure modes and what breaks

The table lines the three sensors up on the properties that matter for our cone. Read it column by column to see each sensor's weakness, and row by row to see why no single column wins.

CameraLiDARRadar
Depth accuracyPoor alone; inferred, not measuredExcellent, directly measuredModerate, coarse resolution
VelocityInferred across framesInferred across framesMeasured directly (Doppler)
CostCheapestMost expensiveCheap
WeaknessBad in low light/glare; no direct depthSparse at range; expensive; weather-sensitiveCoarse spatial resolution; hard to classify objects

What shows up in production

The first failure is sensor miscalibration. Extrinsics drift out of alignment over time, from a bump, a temperature change or a minor collision. Every downstream fusion step then silently trusts a wrong camera-to-vehicle transform, producing subtly wrong 3D positions that look entirely plausible. Our cone would still be detected, but a metre away from where it is.

The second is long-tail object shapes that a bounding-box detector's training categories never covered. Occupancy networks are built to catch these, and pure bounding-box pipelines fail on them quietly instead of loudly.

The third is radar and camera disagreement in edge cases. A large stationary metal object can produce a weak or ambiguous radar return. If the fusion logic over-trusts radar's usually reliable velocity signal, a real stationary hazard can be under-weighted.

The fourth is compounding error across stages. Prediction errors feed straight into planning as if they were ground truth, so an overconfident, wrong trajectory forecast for another vehicle produces a planning decision that is optimal for the wrong predicted future.

These failures share a lesson that cuts against a common belief, namely that more sensors are strictly more robust. They aren't, automatically, because fusion has to correctly handle sensors that disagree. A fusion system with a bad prior, one that over-trusts a modality or works from a subtly miscalibrated extrinsic transform, can produce a worse combined estimate than the single best sensor would have given alone. Sensor diversity only helps if the fusion logic knows how much to trust each sensor under current conditions, and that's a real design problem that doesn't come free with more data streams.

As for where things stand in 2026, BEV transformers and occupancy networks are the deployed standard for perception on modern multi-camera (and camera plus LiDAR) stacks. Modular pipelines, meaning separate perception, prediction and planning stages, remain the deployed default for safety-critical systems. End-to-end driving is an active, fast-moving research area with promising benchmark results. It hasn't broadly displaced modular pipelines in safety-certified production systems, and claims that it has should be treated skeptically absent a specific, verifiable source.

06Summary

  1. A camera loses depth, and the projection equation says exactly how. The scale factor in is the depth, and a single pixel is consistent with every distance along its ray.
  2. Intrinsics and extrinsics do two different jobs. Extrinsics move a point from the vehicle frame into a camera's frame, intrinsics project it to a pixel, and a multi-camera rig needs every extrinsic measured against one shared frame.
  3. A second camera gets depth back through epipolar geometry. The constraint reduces matching to a 1D search along a line, and disparity is inversely proportional to depth for a fixed baseline.
  4. Camera, LiDAR and radar are complementary, not redundant. The camera brings semantics, LiDAR brings precise geometry, and radar brings direct velocity through Doppler, and each fails where another succeeds.
  5. SLAM and PointPillars solve awkward problems with simple moves. SLAM estimates the trajectory and the map together, with an IMU and a camera covering each other, and PointPillars turns a sparse point cloud into a 2D pseudo-image an ordinary CNN can read.
  6. A bird's-eye-view grid is the shared frame for driving. BEVFormer fills it with spatial cross-attention over the cameras and temporal self-attention over the previous grid, which helps with velocity and with briefly occluded objects.
  7. Occupancy networks describe space instead of naming objects. Predicting occupied cells survives shapes no category list names, and TPVFormer keeps it affordable with three orthogonal 2D planes.
  8. Fuse features before detection, in the middle. Late fusion discards partial evidence before it can be combined, and intermediate-feature fusion in a shared grid is the favored compromise.
  9. Prediction must be multimodal, and planning must be safe, comfortable and legal. Averaging two plausible futures gives a path nobody takes, and the planner searches for a trajectory against all the predicted ones.
  10. Modular stays the deployed default because it can explain itself. End-to-end may find a jointly better solution, but regulators and post-incident investigations need to know which stage was responsible.
  11. Calibration and fusion trust are where stacks fail. A drifted extrinsic produces confident, plausible, wrong geometry, and over-trusting one sensor can leave the fused estimate worse than the best single sensor.

07Build this

The projection equation in section 02 throws depth away in a single line. Recovering it from two photographs, with your own code, is what makes the rest of this page feel mechanical instead of magical.

Project Recover depth from a stereo pair, then break the calibration ~3 hours · NumPy

Take one rectified stereo pair from a public driving dataset and compute a disparity map by hand. Turn it into depth, then drop the result into the smallest possible bird's-eye-view grid. Two real photographs, about a hundred lines. Everything BEVFormer adds on top of this is learned. This part is not, and it is worth seeing that geometry alone already puts objects roughly where they belong.

  1. Download one rectified stereo pair and its calibration from a public benchmark. KITTI's stereo set is the usual choice. Rectified means corresponding pixels already sit on the same image row. Note the focal length in pixels and the baseline in metres.
  2. Write block matching yourself. For each pixel in the left image, slide a small window along the same row of the right image. Score each shift by sum of absolute differences and keep the best. That 1D search along a row is the epipolar constraint from section 02, cashed in. No cv2.StereoBM. Downscale the pair if the loop crawls.
  3. Convert with and show the disparity map beside the left image. Pick a few pixels by hand: a car just ahead, a car further down the road, a building at the end of the street. Compare their depths against each other.
  4. Back-project every pixel into vehicle-frame 3D by inverting the projection equation from section 02. Bin the points into a top-down grid of, say, 20 cm cells and plot the counts. That grid is a BEV with no learning in it at all.
  5. Now break the calibration. Change the baseline by a few percent and rerun everything, with the images untouched.
  6. Restore the baseline. Instead rotate the assumed camera extrinsic by a fraction of a degree, rerun, and look at the BEV again.
You'll know it worked when the disparity map is bright on near surfaces and dark on far ones, with edges where object edges are. The BEV grid should put a blob near the bottom for the car ahead, and a band at the far edge for the buildings. Nothing you wrote knows what a car is. That layout came out of geometry.
What the two breakages teach. A wrong baseline scales every depth by a constant, so the disparity map looks exactly as convincing as before and the BEV is uniformly wrong. Nothing in either picture flags it. A small extrinsic rotation is nastier. It tilts the whole point cloud, so the ground plane slopes and far points slide sideways much further than near ones. That is the miscalibration failure mode from section 05, reproduced in a few lines. Calibration errors do not look like errors. They look like confident, plausible, wrong geometry, which is why a real stack spends so much effort on staying calibrated.

Where this runs in production

A representative modern stack runs five stages:

  • Sense. Six to eight cameras around the vehicle, sometimes paired with LiDAR.
  • Fuse. A BEV transformer lifts every camera's features into one shared top-down grid, fusing across cameras and across the last few timesteps in the same step.
  • Detect and track. Running on the fused BEV grid, producing tracked objects with position, velocity and a class.
  • Predict. A trajectory predictor takes those tracks plus map context and forecasts several plausible short-horizon futures per agent.
  • Plan and execute. A planner searches candidate ego trajectories against all those predictions plus map and traffic-rule constraints. The winning trajectory goes to a classical trajectory-tracking controller (21).

Public benchmarks like nuScenes and the Waymo Open Dataset exist so different groups' perception and prediction stacks can be compared against the same real, sensor-synchronized driving logs, rather than each group's own private data.

08Interview questions

BeginnerWhy do self-driving cars need multiple sensor types instead of just one really good camera?

Because each sensor fails differently. Cameras are cheap and semantically rich but only give a 2D projection — depth has to be inferred, not measured, and they degrade badly in low light or glare. LiDAR measures 3D geometry directly and precisely, but it's expensive, sparse at range, and tells you nothing about color or texture. Radar measures velocity directly via Doppler shift — something neither camera nor LiDAR does without inferring it across multiple frames — but at coarse spatial resolution. No single sensor covers all three needs (rich semantics, precise geometry, direct velocity), so fusion isn't a nice-to-have, it's structurally required.

BeginnerWhat's the difference between a camera's intrinsics and extrinsics?

Intrinsics describe properties fixed by the camera itself — focal length and principal point — and map a 3D point already in the camera's own coordinate frame to a 2D pixel. Extrinsics describe where the camera is physically mounted and how it's oriented relative to some external reference frame — a rotation and translation converting a point from that external frame into the camera's frame, before intrinsics take over. A multi-camera rig needs every camera's extrinsics relative to one shared frame so their detections can be placed consistently relative to each other.

IntermediateHow does BEVFormer turn several camera images into one shared representation?

It defines a fixed grid of learned query vectors, one per cell of a top-down bird's-eye-view grid. Each query uses spatial cross-attention to pull in features from whichever camera views actually observe that patch of ground, using known camera geometry to know where to look. It also uses temporal self-attention against the previous timestep's BEV grid, which helps estimate velocity and recover briefly-occluded objects, since the model isn't reconstructing the scene from scratch every single frame. The result is one shared top-down feature grid that detection, tracking, and everything downstream can consume, instead of per-camera detections that have to be merged after the fact.

IntermediateWhy would you use an occupancy network instead of a standard 3D object detector?

A bounding-box detector assumes a fixed, closed set of object categories decided at training time, and real driving reliably produces obstacles that don't fit any of them — a fallen ladder, spilled cargo, debris. An occupancy network predicts, per grid cell, whether space is occupied and roughly what kind of thing occupies it, which degrades gracefully on unusual shapes instead of failing to detect them at all, because it never had to commit to a specific named category to register that the space is occupied.

DeepWhy hasn't the industry converged on end-to-end driving despite its promise of joint optimization?

End-to-end driving optimizes one network against a single end task loss, which can in principle discover jointly better solutions a modular pipeline's separately-trained stages can't see — a slightly different detection behavior that happens to produce a much better downstream plan, for instance. The cost is interpretability: when a modular pipeline makes a bad decision, you can inspect which stage — perception, prediction, or planning — was responsible, and validate each stage independently against held-out data for that specific sub-problem. An end-to-end network's decision doesn't decompose that way. For a safety-critical system that needs a debuggable, auditable answer to "why did the car do that," that loss of interpretability is a real cost, which is why modular pipelines remain the deployed default even though end-to-end methods post competitive results on research benchmarks.

DeepWhy is stereo depth estimation less reliable at long range than short range?

Depth is inversely proportional to disparity for a fixed camera baseline and focal length. At long range, disparity is already small — a handful of pixels — so a fixed amount of pixel-matching noise (say, one pixel of error) is a much larger relative error on a small disparity value than the same one-pixel error would be on the large disparity of a nearby object. That's a direct geometric consequence of the depth-disparity relationship, not a fixable calibration issue — it's why LiDAR, which measures range directly rather than through disparity, tends to be trusted more than stereo camera depth at longer distances.

09Go deeper

●Now write it yourself

Reading the derivation and being able to produce it are different skills. These are Deep-ML problems that exercise what this page covers — each one is checked against real test cases, not multiple choice.

Matched to this page from Deep-ML's catalogue of 1,380 problems. More at deep-ml.com, and Where to practise covers the other platforms and what each one trains.