Image Segmentation
Keras
English
adas
autonomous-driving
unet
lane-detection
semantic-segmentaion
computer-vision
Instructions to use dlckdtjq153/road-lane-semantic-segmentation-unet-resnet50 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use dlckdtjq153/road-lane-semantic-segmentation-unet-resnet50 with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://dlckdtjq153/road-lane-semantic-segmentation-unet-resnet50") - Notebooks
- Google Colab
- Kaggle
File size: 5,741 Bytes
7395e1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ---
license: apache-2.0
datasets:
- yaraa11/enhanced-road-segmentation-dataset
language:
- en
pipeline_tag: image-segmentation
tags:
- adas
- autonomous-driving
- unet
- lane-detection
- semantic-segmentaion
- computer-vision
---
# 🛣️ Road & Lane Semantic Segmentation (U-Net with ResNet-50 Encoder)
## Model Description
This model performs **multi-class semantic segmentation for driving scenes**, focusing on:
- **Background**
- **Drivable road area**
- **Lane markings**
It is designed as a perception module similar to those used in **ADAS and autonomous driving pipelines**, where structured lane visualization is derived directly from segmentation outputs (no classical lane detection or Hough transform is used).
The model follows a **U-Net–style encoder–decoder architecture** with a **ResNet-50 backbone** pre-trained for feature extraction.
---
## Architecture
- Encoder: ResNet-50 (pre-trained)
- Decoder: U-Net–style upsampling path with skip connections
- Output: Softmax over 3 classes
- `0`: Background
- `1`: Road
- `2`: Lane markings
---
## Intended Use
This model can be used for:
- Academic research in road scene understanding
- ADAS perception experiments
- Lane visualization systems based on segmentation
- Educational projects in computer vision and deep learning
### Limitations
- Not intended for real-world autonomous driving deployment
- Performance may degrade under:
- Night conditions
- Heavy rain or fog
- Unusual camera angles
- Fine-tuning is recommended for different countries, road types, or camera setups
---
## Repository
Full training, fine-tuning, and inference pipelines are available [here](https://github.com/yaraeslamm/lane-detection)
---
## Training Data
The model was trained on a **custom enhanced dataset**, originally based on:
- **Semantic Segmentation Makassar (IDN) Road Dataset**
(~374 labeled images)
### Dataset Enhancements
To improve generalization, the dataset was expanded using:
- Random rotations
- Horizontal flipping
- Brightness and contrast jitter
Final dataset size: **~1,496 images**
The dataset is publicly available and not included in this repository due to size constraints.
---
## Training Procedure
- Loss Function: Sparse Categorical Crossentropy
- Optimizer: Adam
- Learning Rate: `1e-4`
- Epochs: 20
- Metrics:
- Sparse Categorical Accuracy
- Mean IoU
- Lane-class IoU
Multiple experiments were conducted with different augmentation strategies and training schedules.
Final model selection prioritized **lane IoU stability and visual consistency**, not only numerical metrics.
---
## Class Mapping
| Class ID | Label |
|--------:|-------------|
| 0 | Background |
| 1 | Road |
| 2 | Lane Markings |
---
## Evaluation Results
| Metric | Training | Validation |
|--------|----------|------------|
| Accuracy | 0.9972 | 0.9954 |
| Mean IoU | 0.9456 | 0.9401 |
| Lane IoU | 0.8517 | 0.8542 |
| Loss | 0.0069 | 0.0146 |
---
## How to Use
This model is intended to be used with custom inference pipelines.
Typical inference steps:
1. Resize input image to model input size
2. Normalize pixel values
3. Run forward pass
4. Apply `argmax` over softmax output to get class IDs
5. Visualize lane pixels or overlay segmentation mask
### Example (TensorFlow / Keras)
```python
import tensorflow as tf
import cv2
import numpy as np
# -------- Load model --------
model = tf.keras.models.load_model(
"model_path",
compile=False
)
# -------- Load & preprocess image --------
img_path = "image_path"
orig = cv2.imread(img_path)
orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB)
img = cv2.resize(orig, (256, 256))
img_norm = img / 255.0
img_input = np.expand_dims(img_norm, axis=0)
# -------- Predict --------
pred = model.predict(img_input)
mask = np.argmax(pred[0], axis=-1) # (256, 256)
# -------- Create color mask --------
# Class mapping:
# 0 = background, 1 = road, 2 = lane
color_mask = np.zeros((256, 256, 3), dtype=np.uint8)
color_mask[mask == 1] = (255, 0, 0) # Road -> Red
color_mask[mask == 2] = (0, 255, 0) # Lane -> Green
# -------- Overlay full segmentation --------
overlay_full = cv2.addWeighted(img.astype(np.uint8), 0.6, color_mask, 0.4, 0)
# -------- Lane-only overlay --------
lane_mask = np.zeros_like(color_mask)
lane_mask[mask == 2] = (0, 255, 0)
overlay_lane = cv2.addWeighted(img.astype(np.uint8), 0.7, lane_mask, 0.3, 0)
# -------- Show results --------
cv2.imshow("Original", cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2BGR))
cv2.imshow("Segmentation Overlay (Road + Lane)", cv2.cvtColor(overlay_full, cv2.COLOR_RGB2BGR))
cv2.imshow("Lane Only Overlay", cv2.cvtColor(overlay_lane, cv2.COLOR_RGB2BGR))
cv2.waitKey(0)
cv2.destroyAllWindows()
```
For full pipelines including video processing and lane visualization,
see the [GitHub repository](https://github.com/yaraeslamm/lane-detection)
---
## Fine-Tuning
Fine-tuning is recommended if:
- Using different road environments
- Working with different camera perspectives
- Wanting to rebalance lane vs road classes
Training scripts support:
- Freezing the encoder
- Full model retraining
- Custom datasets with RGB masks converted to class IDs
---
## Ethical Considerations
This model is intended for **research and educational purposes only**.
It should not be used as a sole perception system in safety-critical or real-world autonomous driving applications.
---
## License
This model is released under the **Apache 2.0 License**, allowing commercial and research use with attribution.
---
## Author
Developed by Yara Elshehawi
Check out my other work:
[Portfolio](https://yaraeslamm.github.io)
[LinkedIn](https://www.linkedin.com/in/yara-eslam-877421212/)
|