How chequanghuy/twinlitenet works
Project Type and Purpose
• TwinLiteNet is a pure machine‐learning pipeline for drivable‐area segmentation and lane detection. It is not a client-server or full-stack web app but an end-to-end deep-learning system that covers data ingestion, model definition, training, validation, inference, and export.
File Structure
Top‐level files and directories:
• DataSet.py → Dataset class and data loader logic
• IOUEval.py → Metric computation (IoU, lane metrics)
• const.py → Global constants and configuration keys
• export.py → Model‐export utilities (ONNX/TensorRT)
• loss.py → Loss functions (segmentation + lane)
• model/ → Model architecture: TwinLite.py
• pretrained/ → Checkpoints (best.pth)
• train.py → Training loop, optimizer, checkpointing
• val.py → Validation loop
• test_image.py → Offline inference on single images
• test_trt.py → Inference with TensorRT engine
• utils.py → Helper routines (logging, visualization)
• requirements.txt → Dependencies
README for Insights
• Confirms the pipeline stages: Data Preparation → Training → Testing → Inference → Visualization.
• Specifies external dataset (BDD100K) and external libraries (PyTorch, TensorRT).
Main Components
a. Data Ingestion & Preprocessing
• Block: “BDD100K Data (images + annotations)”
• Component: DataSet.py
• Output: preprocessed batches
b. Model
• Block: “TwinLiteNet Architecture”
• Location: model/TwinLite.py
• Subcomponents: shared encoder, two decoders (drivable area head, lane head)
c. Loss & Metrics
• Block: “Loss Computation” → loss.py
• Block: “Metric Evaluation” → IOUEval.py
d. Training Orchestration
• Block: train.py
• Interactions: takes data batches and model, applies loss, optimizer, scheduler, checkpoints to pretrained/
e. Validation
• Block: val.py
• Interaction: loads checkpoint, runs data through model, computes metrics
f. Inference
• Blocks: test_image.py (PyTorch) and test_trt.py (TensorRT)
• export.py: ONNX/TensorRT conversion
g. Utilities
• utils.py: logging, visualization, saving images
Relationships and Data Flow
1. Raw Dataset → DataSet.py → DataLoader batches
2. Batches → TwinLiteNet → Predictions
3. Predictions + Ground Truth → loss.py → Loss
4. Loss → train.py optimizer step → updated model → checkpoint
5. Checkpoint → val.py → IOUEval.py → Metrics
6. Final Checkpoint → export.py → ONNX/TensorRT engine → test_trt.py
7. Inference outputs → utils.py → visualization
Architectural Patterns & Design Principles
• Modular separation of concerns: data / model / loss / orchestration / utils.
• Encoder–Decoder architecture with dual heads.
• Checkpointing for reproducibility.
• Export layer decoupled from core model.
• Use of external services (PyTorch, TensorRT) abstracted in export.py and test_trt.py.
Relevant Technologies
• Python 3.x, PyTorch (model training), TorchMetrics/Custom IOU (metrics),
• ONNX + TensorRT (export/inference acceleration), CUDA (GPU compute),
• Common libraries: numpy, opencv, tensorboard.