2026
Monocular 3D Vehicle Detection on Mobile
A lightweight single-camera 3D car detector for KITTI. A MobileNetV2 + FPN backbone and a CenterNet-style head predict full 3D boxes from one RGB image, exported to a 5 MB TFLite model.
- Single RGB image → 3D boxes
- MobileNetV2 + FPN backbone
- TFLite, fp16 weights, ~5 MB
- 384 × 1280 input
The problem
Most 3D object detectors depend on LiDAR or stereo cameras and large backbones. I wanted to see how far a single camera and a phone-sized network can go: given one RGB frame and the camera’s calibration, predict each car’s 3D position, size and heading.
How it works
The head runs on a single feature level (P2, stride 4) and predicts, for every pixel:
- Heatmap: how likely an object center is there, trained with CenterNet’s penalty-reduced focal loss.
- Offset: a sub-pixel (x, y) correction to the peak location.
- Depth: encoded as
1 / (1 + z)so near and far cars both train stably. - Dimensions: log residuals of (h, w, l) against the dataset’s mean car size.
- Orientation: (sin, cos) of the local observation angle α.
At inference, peaks are taken from the heatmap. Pixel location and depth are back-projected through
the pinhole camera model to a 3D centroid. Heading comes from rotation_y = α + atan2(x, z).
Engineering details
- Target encoding. Each ground-truth car’s 3D centroid is projected through
P2onto the stride-4 grid and splatted as a Gaussian sized with the standard CenterNet radius formula. Targets are packed into fixed-size arrays with a validity mask, since TensorFlow needs static shapes. - Leak-free validation. KITTI frames come from continuous drives, so a random split leaks
near-duplicate scenes into validation. With KITTI’s
train_mapping.txtthe split is done by whole drive sequence instead. - Evaluation. Rotated-box BEV and 3D IoU, 40-point interpolated AP at IoU 0.7, plus depth MAE and orientation error on matched detections, all logged to TensorBoard each epoch.
- Resumable training. A custom loop checkpoints weights and the epoch counter, so a run can be stopped and picked up again.
- Pipeline sanity check. A script fabricates a synthetic KITTI sample and pushes it through parsing, target encoding, a forward pass, the loss, a gradient step and decoding, so wiring bugs show up without downloading the dataset.
- Deployment. The trained model is exported to TFLite with fp16 weights (about 5 MB), with a golden input/output pair to check the on-device port against.
Limitations and next steps
- Single class (Car) and a single feature level; no multi-scale fusion yet.
- No data augmentation or learning-rate schedule.
- The metrics are a simplified stand-in for KITTI’s official evaluation (one difficulty tier), useful for tracking progress but not for comparing with published numbers.
Cover image: frame 000161 from the KITTI Vision Benchmark Suite (Geiger et al.), CC BY-NC-SA 3.0.