mlboydaisuke commited on
Commit
089cbfc
·
verified ·
1 Parent(s): 9674a4a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +95 -0
README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: litert
4
+ pipeline_tag: image-segmentation
5
+ tags:
6
+ - litert
7
+ - tflite
8
+ - android
9
+ - on-device
10
+ - gpu
11
+ - lane-detection
12
+ - adas
13
+ - autonomous-driving
14
+ - real-time
15
+ ---
16
+
17
+ # Ultra-Fast-Lane-Detection (ResNet18, CULane) — LiteRT GPU
18
+
19
+ On-device **lane detection** running **fully on the LiteRT `CompiledModel` GPU**
20
+ delegate (no CPU fallback). [Ultra-Fast-Lane-Detection](https://github.com/cfzd/Ultra-Fast-Lane-Detection)
21
+ (ECCV 2020) reformulates lane detection as fast **row-wise classification** — the
22
+ network runs on the GPU, and a tiny host-side arg/expectation decode turns the grid
23
+ into lane points. ~20 ms/frame on a Pixel 8a.
24
+
25
+ - **Architecture:** ResNet18 backbone + row-anchor classification head — pure CNN.
26
+ - **Weights:** [cfzd/Ultra-Fast-Lane-Detection](https://github.com/cfzd/Ultra-Fast-Lane-Detection) (CULane, ResNet18) · MIT.
27
+ - **Size:** 178 MB.
28
+
29
+ ![Ultra-Fast-Lane-Detection](hero.png)
30
+
31
+ *Detected ego-lane on a dashcam highway frame. Source: Wikimedia Commons (Public Domain).*
32
+
33
+ ## I/O
34
+
35
+ - **Input:** `[1, 3, 288, 800]` NCHW, RGB, `x/255` then ImageNet-normalized
36
+ (mean `[0.485,0.456,0.406]`, std `[0.229,0.224,0.225]`).
37
+ - **Output:** `[1, 201, 18, 4]` = `(griding+1, row_anchors, lanes)` — per-lane, per-row
38
+ classification logits over 200 horizontal grid cells (+1 "no lane").
39
+
40
+ ## Host-side decode
41
+
42
+ For each of the 4 lanes and 18 row anchors: softmax over the 200 grid cells, take the
43
+ expectation → column; if the argmax over all 201 is the last index (200 = "no lane"),
44
+ drop it. Map the column to an x-pixel via `linspace(0, 799, 200)` (scaled to the image
45
+ width) and the row anchor to a y-pixel (CULane row anchors, scaled from 288).
46
+
47
+ ## GPU conversion
48
+
49
+ UFLD is a pure CNN. It converts fully GPU-compatible (**41/41 nodes on the delegate,
50
+ 1 partition**; device corr 0.999982, ~20 ms) with **one patch**: the ResNet18 stem
51
+ `MaxPool2d(padding=1)` lowers to a `-inf` PADV2 (rejected by Mali), replaced by a 0-pad
52
+ + unpadded maxpool (exact post-ReLU). CPU-exact vs PyTorch (corr 0.9999999999996).
53
+
54
+ ## Minimal usage
55
+
56
+ ### Kotlin (Android, LiteRT CompiledModel GPU)
57
+
58
+ ```kotlin
59
+ val options = CompiledModel.Options(Accelerator.GPU)
60
+ val model = CompiledModel.create(context.assets, "ufld.tflite", options, null)
61
+ val inBufs = model.createInputBuffers()
62
+ val outBufs = model.createOutputBuffers()
63
+
64
+ inBufs[0].writeFloat(inputNCHW) // [1,3,288,800] RGB, x/255 then ImageNet-norm
65
+ model.run(inBufs, outBufs)
66
+ val out = outBufs[0].readFloat() // [201*18*4], layout (griding+1, rows, lanes)
67
+ // decode: per (lane,row) softmax over the first 200 cells, take the expectation -> column;
68
+ // skip if argmax == 200 (no lane). See LaneDetector.kt for the full decode.
69
+ ```
70
+
71
+ ### Python (LiteRT / ai-edge-litert)
72
+
73
+ ```python
74
+ import numpy as np
75
+ from ai_edge_litert.interpreter import Interpreter
76
+
77
+ it = Interpreter(model_path="ufld.tflite"); it.allocate_tensors()
78
+ inp, out = it.get_input_details(), it.get_output_details()
79
+ it.set_tensor(inp[0]["index"], x) # [1,3,288,800] float32, RGB /255, ImageNet-norm
80
+ it.invoke()
81
+ o = it.get_tensor(out[0]["index"])[0] # [201,18,4]
82
+ o = o[:, ::-1, :]
83
+ prob = np.exp(o[:-1]) / np.exp(o[:-1]).sum(0, keepdims=True)
84
+ loc = (prob * (np.arange(200) + 1).reshape(-1, 1, 1)).sum(0) # [18,4] columns
85
+ loc[np.argmax(o, 0) == 200] = 0 # 0 = no lane
86
+ ```
87
+
88
+ ## Conversion
89
+
90
+ Converted with **litert-torch** (`build_ufld.py`): loads the ResNet18 CULane weights and
91
+ exports the row-classification graph.
92
+
93
+ ## License
94
+
95
+ MIT (Ultra-Fast-Lane-Detection / cfzd). Trained on CULane.