mlboydaisuke's picture
Upload README.md with huggingface_hub
089cbfc verified
|
Raw
History Blame Contribute Delete
3.58 kB
---
license: mit
library_name: litert
pipeline_tag: image-segmentation
tags:
- litert
- tflite
- android
- on-device
- gpu
- lane-detection
- adas
- autonomous-driving
- real-time
---
# Ultra-Fast-Lane-Detection (ResNet18, CULane) — LiteRT GPU
On-device **lane detection** running **fully on the LiteRT `CompiledModel` GPU**
delegate (no CPU fallback). [Ultra-Fast-Lane-Detection](https://github.com/cfzd/Ultra-Fast-Lane-Detection)
(ECCV 2020) reformulates lane detection as fast **row-wise classification** — the
network runs on the GPU, and a tiny host-side arg/expectation decode turns the grid
into lane points. ~20 ms/frame on a Pixel 8a.
- **Architecture:** ResNet18 backbone + row-anchor classification head — pure CNN.
- **Weights:** [cfzd/Ultra-Fast-Lane-Detection](https://github.com/cfzd/Ultra-Fast-Lane-Detection) (CULane, ResNet18) · MIT.
- **Size:** 178 MB.
![Ultra-Fast-Lane-Detection](hero.png)
*Detected ego-lane on a dashcam highway frame. Source: Wikimedia Commons (Public Domain).*
## I/O
- **Input:** `[1, 3, 288, 800]` NCHW, RGB, `x/255` then ImageNet-normalized
(mean `[0.485,0.456,0.406]`, std `[0.229,0.224,0.225]`).
- **Output:** `[1, 201, 18, 4]` = `(griding+1, row_anchors, lanes)` — per-lane, per-row
classification logits over 200 horizontal grid cells (+1 "no lane").
## Host-side decode
For each of the 4 lanes and 18 row anchors: softmax over the 200 grid cells, take the
expectation → column; if the argmax over all 201 is the last index (200 = "no lane"),
drop it. Map the column to an x-pixel via `linspace(0, 799, 200)` (scaled to the image
width) and the row anchor to a y-pixel (CULane row anchors, scaled from 288).
## GPU conversion
UFLD is a pure CNN. It converts fully GPU-compatible (**41/41 nodes on the delegate,
1 partition**; device corr 0.999982, ~20 ms) with **one patch**: the ResNet18 stem
`MaxPool2d(padding=1)` lowers to a `-inf` PADV2 (rejected by Mali), replaced by a 0-pad
+ unpadded maxpool (exact post-ReLU). CPU-exact vs PyTorch (corr 0.9999999999996).
## Minimal usage
### Kotlin (Android, LiteRT CompiledModel GPU)
```kotlin
val options = CompiledModel.Options(Accelerator.GPU)
val model = CompiledModel.create(context.assets, "ufld.tflite", options, null)
val inBufs = model.createInputBuffers()
val outBufs = model.createOutputBuffers()
inBufs[0].writeFloat(inputNCHW) // [1,3,288,800] RGB, x/255 then ImageNet-norm
model.run(inBufs, outBufs)
val out = outBufs[0].readFloat() // [201*18*4], layout (griding+1, rows, lanes)
// decode: per (lane,row) softmax over the first 200 cells, take the expectation -> column;
// skip if argmax == 200 (no lane). See LaneDetector.kt for the full decode.
```
### Python (LiteRT / ai-edge-litert)
```python
import numpy as np
from ai_edge_litert.interpreter import Interpreter
it = Interpreter(model_path="ufld.tflite"); it.allocate_tensors()
inp, out = it.get_input_details(), it.get_output_details()
it.set_tensor(inp[0]["index"], x) # [1,3,288,800] float32, RGB /255, ImageNet-norm
it.invoke()
o = it.get_tensor(out[0]["index"])[0] # [201,18,4]
o = o[:, ::-1, :]
prob = np.exp(o[:-1]) / np.exp(o[:-1]).sum(0, keepdims=True)
loc = (prob * (np.arange(200) + 1).reshape(-1, 1, 1)).sum(0) # [18,4] columns
loc[np.argmax(o, 0) == 200] = 0 # 0 = no lane
```
## Conversion
Converted with **litert-torch** (`build_ufld.py`): loads the ResNet18 CULane weights and
exports the row-classification graph.
## License
MIT (Ultra-Fast-Lane-Detection / cfzd). Trained on CULane.