Lane detection U-Net (ResNet-34), TuSimple
U-Net with a ResNet-34 encoder that labels every pixel of a front-camera road image with its lane slot: background, outer-left, ego-left, ego-right or outer-right. Lanes are then recovered from the per-row probability peaks and a low-order polynomial fit.
Code, training and evaluation: github.com/haroonkhan02/lane-detection-classical-vs-deep.
Results
TuSimple test set, 2,782 images, official accuracy / FP / FN metric.
| Lanes scored | Accuracy | FP | FN |
|---|---|---|---|
| Ego (the two lanes bounding the car's lane) | 0.951 | 0.053 | 0.051 |
| All lanes (standard protocol) | 0.950 | 0.049 | 0.062 |
About 21 ms per 1280x720 frame on an Apple M5 (MPS), including pre- and post-processing.
Training
- Data: TuSimple train + val label files (3,268 training images), input resized to 512x288.
- Loss: weighted cross-entropy + Dice (lane pixels are about 2 % of the image).
- 30 epochs, checkpoint chosen by TuSimple ego accuracy on the validation split (epoch 28, 0.935).
Usage
from huggingface_hub import hf_hub_download
from lanedet.deep.model import DeepLaneDetector # pip install git+https://github.com/haroonkhan02/lane-detection-classical-vs-deep
detector = DeepLaneDetector(hf_hub_download("haroonx02/lane-detection-unet-resnet34", "unet_resnet34_full.pt"))
result = detector(bgr_image) # LaneResult with one polyline per lane slot
The file is a plain torch.save dict (state_dict, encoder, input_size, epoch,
val_ego_acc); load it with torch.load(..., weights_only=False) only if you trust this repo.
ONNX and the in-browser demo
onnx/ holds exports that take an RGB image in [0, 1] (1x3x288x512) and return softmax
probabilities (1x5x288x512); normalisation and softmax are inside the graph. Re-scored on the
full TuSimple test set:
| File | Size | Ego accuracy | Ego FP | Ego FN |
|---|---|---|---|---|
unet_resnet34_full.pt (PyTorch) |
98 MB | 0.951 | 0.053 | 0.051 |
onnx/lane_unet_fp16.onnx |
49 MB | 0.951 | 0.053 | 0.051 |
onnx/lane_unet_int8.onnx (static QDQ, 128 calibration frames) |
25 MB | 0.950 | 0.056 | 0.054 |
The INT8 file runs in the browser with onnxruntime-web: huggingface.co/spaces/haroonx02/lane-detection-browser.
Limitations
Daytime highway images from one camera. It does not generalise to other cameras, night, rain or city streets: on the Udacity challenge video it produces unstable curves. Not for use in a vehicle.