Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Multi-Function ADAS Implementation Using YOLO Series, ByteTrack, and UFLDv2

Tech Jul 28 1

Core Components

The system integrates real-time vehicle detection, lane marking extraction, and multi-object tracking to deliver three driver-assistance capabilities: forward collision alert, lane departure alert, and lane keeping assistance. It supports interchangeable detection backends including YOLOv5 through YOLOv11, EfficientDet, and processes video streams from dashcams or embedded boards such as Jetson Nano, RK3588, or Raspberry Pi.

Detection Backbone

A flexible detector interface allows selection among YOLO variants and EfficientDet. Each model is loaded via ONNX for cross-platform ifnerence. Example configuration for YOLOv9:

vehicle_cfg = {
    "weight_file": "./models/v9_car_det.onnx",
    "det_type": "YOLOv9",
    "label_file": "./models/coco_classes.txt",
    "conf_thresh": 0.4,
    "iou_thresh": 0.5
}

Internally, detections are parsed into normalized bounding boxes and passed to downstream logic.

Lane Marking Extraction

Ultra Fast Lane Detection v2 (UFLDv2) models lane lines as sequential classification over sparse anchors, enabling high-speed inference (>300 FPS). The CULane variant is used here. After perspective transformation to bird’s-eye view, the algorithm outputs:

  • Offset: Lateral displacement of ego-vehicle center relative to lane center (positive if leftward).
  • R: Mean curvature radius of detected lanes (large R implies straighter road).

Configuration example:

lane_cfg = {
    "weight_file": "./models/ufldv2_cu_res18.onnx",
    "lane_type": "UFLDv2_CULANE"
}

Multi-Object Tracking

ByteTrack maintains object identities across frames using Kalman prediction and Hungarian matching. Unlike ReID-based approaches, it retains low-confidence detections for a second matching pass, reducing ID switches under occlusion. The pipeline:

  1. Split detections into high-score and low-score sets.
  2. Match high-score detections to existing tracks.
  3. Rematch unassociated tracks with low-score detections using IoU only.
  4. Initialize new tracks from remaining high-score boxes.
  5. Retain lost tracks for up to 30 frames before discarding.

Forward Collision Alert (FCWS)

Distance estimation maps image-space measurements to real-world space via a scale factor adjustable per camera setup. A rolling average over five frames smooths noise.

Risk levels:

  • NORMAL ("Normal Risk", green/yellow): No imminent threat.
  • PROMPT ("Prompt Risk", orange-red): Average distance within [threshold, 2×threshold) meters.
  • WARNING ("Warning Risk", red): Average distance below threshold (e.g., 3 m).

Logic outline:

if distance is None:
    status = NORMAL if lead_in_lane else UNKNOWN
elif avg_distance < THRESHOLD:
    status = WARNING
elif avg_distance < 2 * THRESHOLD:
    status = PROMPT
else:
    status = NORMAL

The status flag drives on-screen alerts and can trigger haptic or audio warnings.

Lane Departure Alert (LDWS)

Using Offset and R values:

  • Positive Offset → vehicle right of lane center → suggest "Keep Left".
  • Negative Offset → vehicle left of lane center → suggest "Keep Right".
  • Small magintude Offset → "Good Lane Keeping".

Curvature radius informs upcoming bend severity for LKAS but here serves to validate lane geometry reliability.

Example interpretation:

Offset R (m) LDWS Message
+1.2 3260.2 Please Keep Left
-0.8 4100.0 Please Keep Right
~0.0 5000.0 Good Lane Keeping

Lane Keeping Assistance (LKAS)

A curvature threshold curve_thresh classifies bends:

  • Hard Left/Right: Radius ≤ threshold, direction derived from lane slope.
  • Easy Left/Right: Radius > threshold, directional classification same as above.
  • Straight: Direction indeterminate or radius very large.

Implementation sketch:

if radius <= curve_thresh:
    if direction == "left":
        return "Hard Left Curve Ahead"
    elif direction == "right":
        return "Hard Right Curve Ahead"
elif radius > curve_thresh:
    if direction == "left":
        return "Gentle Left Curve Ahead"
    elif direction == "right":
        return "Gentle Right Curve Ahead"
    else:
        return "Keep Straight Ahead"
else:
    return "To Be Determined ..."

Execution Workflow

Run demo.py directly. Paths for test video and model weights are preset. Adjust lane_config and object_config to match chosen model types and checkpoint files.

Convert ONNX to TensorRT for acecleration:

python convertOnnxToTensorRT.py -i <input.onnx> -o <output.trt>

Quantize ONNX:

python onnxQuantization.py -i <input.onnx>

Supported configurations:

Domain Model Type Description
Lanes UFLD_TUSIMPLE / UFLD_CULANE ResNet18 backbone, Tusimple/CULane data
Lanes UFLDV2_TUSIMPLE / UFLDV2_CULANE ResNet18/34, improved speed & accuracy
Object YOLOv5 / YOLOv5_LITE Standard and lightweight variants
Object YOLOv6 / YOLOv7 / YOLOv8 Various sizes and optimized versions
Object YOLOv9 / YOLOv10 Latest architectures with multiple scales
Object EfficientDet B0–B3 variants

Environment Setup

  • Python ≥ 3.7
  • Packages: OpenCV, scikit-learn, onnxruntime, pycuda, PyTorch
  • Create virtual environment:
conda create -n adas_env python=3.8.5
conda activate adas_env

Install PyTorch GPU build matching CUDA version, e.g.:

conda install pytorch==1.8.0 torchvision torchaudio cudatoolkit=10.2

Install remaining dependencies:

pip install -r requirements.txt

Configure conda and pip to use domestic mirrors for faster downloads.

Tags: ADAS

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.