ML System Design: Intersection Maneuver Intent Prediction
Machine LearningModel answerLast updated
Design an ML pipeline that classifies each vehicle at an intersection as turning left, going straight, or turning right, given a short trajectory history and optional map context.
Intersection Maneuver Intent Prediction
You are building a real-time intent recognition system for an autonomous vehicle. At any intersection, there are n vehicles (typically 5–50) either waiting or approaching. For each vehicle you have a rolling history covering the last 3–10 seconds at 10 Hz, containing:
- Position (x, y) in a map-aligned world frame
- Velocity (vx, vy) and, optionally, acceleration (ax, ay)
- Optionally: lane centerlines, stop-line positions, and allowed maneuvers from an HD map
Your goal is to output, for each vehicle, a probability distribution over three maneuver classes:
| Class | Description |
|---|---|
| Left turn | Vehicle will turn left through the intersection |
| Go straight | Vehicle will continue without turning |
| Right turn | Vehicle will turn right through the intersection |
These predictions feed directly into the ego vehicle's motion planner, so latency, calibration, and failure modes all matter.
Your task: describe how you would design, train, and evaluate this system end-to-end.
Structure your answer around these six areas:
- Labeling strategy and time horizon — how do you define and extract ground-truth intent from logged data?
- Feature engineering vs. learned sequence models — when would you use each, and how do you incorporate map/lane geometry?
- Multi-agent interactions — how do the behaviors of surrounding vehicles affect each agent's predicted intent?
- Evaluation metrics — what do you measure beyond accuracy, and how do you connect metrics to planner safety?
- Data challenges — class imbalance, distribution shift across different intersections and cities, and vehicles that change their mind at the last moment.
- Uncertainty estimation — how do you produce well-calibrated probabilities and use them responsibly in downstream planning?
Hints
Hint 1
Start by asking what the consuming system actually needs. A planner that reacts to intent 3 seconds early has very different requirements than one that acts 0.5 seconds early — this shapes your label definition, your time-horizon evaluation, and your cost matrix before you write a single line of model code.
Hint 2
Labels are free from hindsight: you already know where each logged vehicle went. Think carefully about *when* during the approach you snapshot the input features for a training example — the anchor time index-ed to time-before-entry prevents the model from trivially reading the answer from within-turn heading. Then think about what makes a label ambiguous or invalid (tracking loss, out-of-log vehi…
Hint 3
A lane-conditioned, target-based formulation — scoring each *candidate exit lane* rather than predicting left/straight/right as a fixed 3-way softmax — handles arbitrary intersection geometries and lets the map topology zero out physically impossible classes automatically. This is both a modeling win and a generalization win across cities.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing the Problem
Before touching model architecture, lock down what the system actually needs to do. The predictions are consumed by a motion planner running onboard at 10 Hz with a budget of roughly 10–20 ms for all agents. That rules out large autoregressive models without aggressive optimization. The prediction horizon of interest is 1–5 seconds before the vehicle crosses the stop line — early enough to be useful, late enough to have meaningful signal.
Also clarify available inputs upfront: turn signal availability, traffic light state, and HD map quality change the design substantially. In the strongest setup, assume you have all three.
1. Labeling Strategy and Time Horizon
Hindsight auto-labeling makes this tractable at scale. Fleet logs capture what every vehicle actually did, so you match each vehicle's exit road segment to its entry segment via the map's lane graph. Net heading change (> +45° = left, < −45° = right, otherwise straight) serves as a fallback when map matching fails.
The key design choice is the anchor time: when during the approach do you snapshot features to form one training example? Index by time-to-stop-line τ, creating multiple examples per traversal at τ = 0.5, 1, 2, 3, 5 s. This buys you:
- Examples at multiple difficulty levels, since early predictions are harder.
- A natural evaluation curve (F1 vs. τ) that communicates early-prediction capability to stakeholders.
- Protection against trivial labels: if you snapshot features inside the turn, the heading already gives the answer away.
Invalid labels to mask rather than default: tracking-ID swaps, vehicles that leave the frame before completing the maneuver, and U-turns (exclude or add a fourth "other" class). Hand-audit a few hundred examples — map-matching errors and tracker swaps are the dominant noise source.
2. Feature Engineering vs. Learned Sequence Models
Start with a gradient-boosted tree baseline on an agent-centric, heading-aligned frame (vehicle heading = +x axis). Strong features:
- Speed, peak deceleration, yaw rate, lateral acceleration over the window.
- Lateral offset from the lane centerline (drift toward the turn side is an early signal).
- Distance remaining to the stop line.
- Lane's allowed maneuvers from the map — a left-turn-only lane is the single highest-information feature in the whole system.
- Turn signal and traffic light phase, if available.
This baseline is fast, interpretable, and competitive. Ship it first.
The main model adds a learned history encoder and a map encoder:
- History encoder: 1D-CNN or GRU over 30–100 steps of (x, y, vx, vy, ax, ay, validity mask) in agent-centric coordinates.
- Map encoder: encode lane polylines with a per-point MLP and max-pool (VectorNet-style), or use a lane graph with graph convolutions (LaneGCN-style).
- Target-based formulation (strongly recommended): enumerate the physically reachable exit lanes from the vehicle's current position. Score each candidate lane with attention between the agent history embedding and the lane embedding. Aggregate per exit lane into left/straight/right via map topology. Infeasible maneuvers get zero probability automatically — no need to learn that a vehicle on a one-way street can't turn left into oncoming traffic. This formulation generalizes far better across irregular intersection geometries (T-junctions, 5-way intersections, skewed angles) than a fixed softmax head.
3. Multi-Agent Interactions
A vehicle braking hard could be yielding to a pedestrian, following a slow lead car, or preparing to turn left. Context from surrounding agents resolves the ambiguity.
- Represent all agents in the scene simultaneously, with relative positions expressed in the target agent's frame.
- Apply agent-to-agent attention (transformer or GNN) over agents within ~50 m, incorporating features like gap to lead vehicle, oncoming vehicle time-to-collision, and whether pedestrians are in crosswalks.
- Interleave agent-to-lane and agent-to-agent attention in stacked layers, following the LaneGCN/Wayformer pattern.
- Marginal per-agent predictions (rather than a full joint distribution) are usually sufficient for intent classification and keep complexity manageable. Only add joint prediction if the planner explicitly requires consistency guarantees.
4. Evaluation Metrics
Accuracy is misleading because "go straight" dominates most intersection datasets. Report:
- Per-class precision, recall, F1, and a confusion matrix. Left-vs-straight is the highest-consequence confusion; flag it explicitly.
- Calibration: Expected calibration error, Brier score, and NLL. The planner consumes probabilities directly — a predicted 0.95 must be right ~95% of the time or you get dangerous overconfidence.
- Early prediction curve: macro-F1 and NLL as a function of τ. Also report time-to-correct-commit: the median seconds before entry at which the model first exceeds a confidence threshold on the true class and stays there.
- Cost-sensitive metrics: missing a left-turner crossing ego's path is far more dangerous than a false alarm (which costs mild braking). Define a cost matrix with the planning team and report expected cost per prediction or recall at a fixed false-positive rate for safety-critical classes.
- Prediction stability: flip rate per second. Rapidly oscillating predictions degrade planner comfort even if mean accuracy is fine.
- Slices: intersection type, city, signalized vs. unsignalized, night vs. day, occluded agents.
Split by intersection or city, never by random example. Random splits leak geometric correlations and inflate metrics by 10–20 percentage points in practice.
5. Class Imbalance, Distribution Shift, Last-Second Changes
Imbalance: use class-weighted cross-entropy or focal loss. Important: weighting distorts the output probabilities relative to the natural prior. Recalibrate with temperature scaling or vector scaling on a natural-distribution validation set afterward, or analytically correct for the prior shift.
Distribution shift across cities: agent-centric and map-relative inputs (not absolute coordinates) remove most intersection-specific memorization. The target-based exit-lane formulation further improves transferability. Train on a geographically diverse corpus, hold out entire cities for evaluation, and monitor online by comparing predicted vs. hindsight labels per intersection type as new deployments roll out.
Last-second intent changes: these are rare but safety-critical. Train on examples at very small τ to represent them, track the posterior update rate online, and flag large confidence reversals (e.g., a drop from P(straight) > 0.9 to P(left) > 0.8 within 0.5 s) as a special signal to the planner rather than silently updating the prediction.
6. Uncertainty Estimation and Downstream Use
The model should output calibrated probabilities, not just argmax labels. Beyond temperature scaling:
- Ensembles (3–5 models with different seeds or architectures) are effective and deployable; their prediction variance is a reliable uncertainty signal.
- MC dropout at inference is lighter weight but less reliable.
- Evidential / Dirichlet-based heads can distinguish in-distribution uncertainty from out-of-distribution inputs.
How the planner uses uncertainty:
- When entropy is high or max probability is below a threshold (e.g., 0.6), the planner should widen its collision buffer for that agent rather than committing to a single assumed trajectory.
- Flag OOD detections (e.g., novel intersection geometry not seen in training) to a monitoring pipeline, not the planner.
- Never hard-threshold a calibrated probability into a binary flag — the whole point of calibration is that the planner can use the soft values in its cost function.
Common Mistakes to Avoid
- Snapshotting features inside the turn and then wondering why the model seems too accurate — the label is leaking through heading.
- Reporting accuracy on a randomly shuffled split and claiming good generalization.
- Skipping calibration evaluation and shipping raw softmax probabilities to the planner.
- Building a transformer before validating that the GBT baseline with map-lane features isn't already at 90%+ for on-lane vehicles — it often is.