Image Segmentation
Keras
English
adas
autonomous-driving
unet
lane-detection
semantic-segmentaion
computer-vision
Instructions to use yaraa11/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 yaraa11/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://yaraa11/road-lane-semantic-segmentation-unet-resnet50") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -145,15 +145,53 @@ import tensorflow as tf
|
|
| 145 |
import cv2
|
| 146 |
import numpy as np
|
| 147 |
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
-
img = cv2.imread("road.jpg")
|
| 151 |
-
img = cv2.resize(img, (INPUT_W, INPUT_H))
|
| 152 |
-
img = img / 255.0
|
| 153 |
-
img = np.expand_dims(img, axis=0)
|
| 154 |
|
| 155 |
-
pred = model.predict(img)
|
| 156 |
-
mask = np.argmax(pred[0], axis=-1)
|
| 157 |
```
|
| 158 |
|
| 159 |
For full pipelines including video processing and lane visualization,
|
|
|
|
| 145 |
import cv2
|
| 146 |
import numpy as np
|
| 147 |
|
| 148 |
+
# -------- Load model --------
|
| 149 |
+
model = tf.keras.models.load_model(
|
| 150 |
+
"model_path",
|
| 151 |
+
compile=False
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
# -------- Load & preprocess image --------
|
| 155 |
+
img_path = "image_path"
|
| 156 |
+
|
| 157 |
+
orig = cv2.imread(img_path)
|
| 158 |
+
orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB)
|
| 159 |
+
|
| 160 |
+
img = cv2.resize(orig, (256, 256))
|
| 161 |
+
img_norm = img / 255.0
|
| 162 |
+
img_input = np.expand_dims(img_norm, axis=0)
|
| 163 |
+
|
| 164 |
+
# -------- Predict --------
|
| 165 |
+
pred = model.predict(img_input)
|
| 166 |
+
mask = np.argmax(pred[0], axis=-1) # (256, 256)
|
| 167 |
+
|
| 168 |
+
# -------- Create color mask --------
|
| 169 |
+
# Class mapping:
|
| 170 |
+
# 0 = background, 1 = road, 2 = lane
|
| 171 |
+
|
| 172 |
+
color_mask = np.zeros((256, 256, 3), dtype=np.uint8)
|
| 173 |
+
|
| 174 |
+
color_mask[mask == 1] = (255, 0, 0) # Road -> Red
|
| 175 |
+
color_mask[mask == 2] = (0, 255, 0) # Lane -> Green
|
| 176 |
+
|
| 177 |
+
# -------- Overlay full segmentation --------
|
| 178 |
+
overlay_full = cv2.addWeighted(img.astype(np.uint8), 0.6, color_mask, 0.4, 0)
|
| 179 |
+
|
| 180 |
+
# -------- Lane-only overlay --------
|
| 181 |
+
lane_mask = np.zeros_like(color_mask)
|
| 182 |
+
lane_mask[mask == 2] = (0, 255, 0)
|
| 183 |
+
|
| 184 |
+
overlay_lane = cv2.addWeighted(img.astype(np.uint8), 0.7, lane_mask, 0.3, 0)
|
| 185 |
+
|
| 186 |
+
# -------- Show results --------
|
| 187 |
+
cv2.imshow("Original", cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2BGR))
|
| 188 |
+
cv2.imshow("Segmentation Overlay (Road + Lane)", cv2.cvtColor(overlay_full, cv2.COLOR_RGB2BGR))
|
| 189 |
+
cv2.imshow("Lane Only Overlay", cv2.cvtColor(overlay_lane, cv2.COLOR_RGB2BGR))
|
| 190 |
+
|
| 191 |
+
cv2.waitKey(0)
|
| 192 |
+
cv2.destroyAllWindows()
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
|
|
|
|
|
|
| 195 |
```
|
| 196 |
|
| 197 |
For full pipelines including video processing and lane visualization,
|