dlckdtjq153 yaraa11 commited on
Commit
7395e1c
·
0 Parent(s):

Duplicate from yaraa11/road-lane-semantic-segmentation-unet-resnet50

Browse files

Co-authored-by: Yara Elshehawi <yaraa11@users.noreply.huggingface.co>

Files changed (3) hide show
  1. .gitattributes +36 -0
  2. README.md +238 -0
  3. road_segmentation.keras +3 -0
.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ road_segmentation.keras filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - yaraa11/enhanced-road-segmentation-dataset
5
+ language:
6
+ - en
7
+ pipeline_tag: image-segmentation
8
+ tags:
9
+ - adas
10
+ - autonomous-driving
11
+ - unet
12
+ - lane-detection
13
+ - semantic-segmentaion
14
+ - computer-vision
15
+ ---
16
+
17
+
18
+ # 🛣️ Road & Lane Semantic Segmentation (U-Net with ResNet-50 Encoder)
19
+
20
+ ## Model Description
21
+
22
+ This model performs **multi-class semantic segmentation for driving scenes**, focusing on:
23
+
24
+ - **Background**
25
+ - **Drivable road area**
26
+ - **Lane markings**
27
+
28
+ 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).
29
+
30
+ The model follows a **U-Net–style encoder–decoder architecture** with a **ResNet-50 backbone** pre-trained for feature extraction.
31
+
32
+ ---
33
+
34
+ ## Architecture
35
+
36
+ - Encoder: ResNet-50 (pre-trained)
37
+ - Decoder: U-Net–style upsampling path with skip connections
38
+ - Output: Softmax over 3 classes
39
+ - `0`: Background
40
+ - `1`: Road
41
+ - `2`: Lane markings
42
+
43
+ ---
44
+
45
+ ## Intended Use
46
+
47
+ This model can be used for:
48
+
49
+ - Academic research in road scene understanding
50
+ - ADAS perception experiments
51
+ - Lane visualization systems based on segmentation
52
+ - Educational projects in computer vision and deep learning
53
+
54
+ ### Limitations
55
+
56
+ - Not intended for real-world autonomous driving deployment
57
+ - Performance may degrade under:
58
+ - Night conditions
59
+ - Heavy rain or fog
60
+ - Unusual camera angles
61
+ - Fine-tuning is recommended for different countries, road types, or camera setups
62
+
63
+ ---
64
+
65
+ ## Repository
66
+
67
+ Full training, fine-tuning, and inference pipelines are available [here](https://github.com/yaraeslamm/lane-detection)
68
+
69
+ ---
70
+
71
+ ## Training Data
72
+
73
+ The model was trained on a **custom enhanced dataset**, originally based on:
74
+
75
+ - **Semantic Segmentation Makassar (IDN) Road Dataset**
76
+ (~374 labeled images)
77
+
78
+ ### Dataset Enhancements
79
+
80
+ To improve generalization, the dataset was expanded using:
81
+
82
+ - Random rotations
83
+ - Horizontal flipping
84
+ - Brightness and contrast jitter
85
+
86
+ Final dataset size: **~1,496 images**
87
+
88
+ The dataset is publicly available and not included in this repository due to size constraints.
89
+
90
+ ---
91
+
92
+ ## Training Procedure
93
+
94
+ - Loss Function: Sparse Categorical Crossentropy
95
+ - Optimizer: Adam
96
+ - Learning Rate: `1e-4`
97
+ - Epochs: 20
98
+ - Metrics:
99
+ - Sparse Categorical Accuracy
100
+ - Mean IoU
101
+ - Lane-class IoU
102
+
103
+ Multiple experiments were conducted with different augmentation strategies and training schedules.
104
+ Final model selection prioritized **lane IoU stability and visual consistency**, not only numerical metrics.
105
+
106
+ ---
107
+
108
+ ## Class Mapping
109
+
110
+ | Class ID | Label |
111
+ |--------:|-------------|
112
+ | 0 | Background |
113
+ | 1 | Road |
114
+ | 2 | Lane Markings |
115
+
116
+ ---
117
+
118
+ ## Evaluation Results
119
+
120
+ | Metric | Training | Validation |
121
+ |--------|----------|------------|
122
+ | Accuracy | 0.9972 | 0.9954 |
123
+ | Mean IoU | 0.9456 | 0.9401 |
124
+ | Lane IoU | 0.8517 | 0.8542 |
125
+ | Loss | 0.0069 | 0.0146 |
126
+
127
+ ---
128
+
129
+ ## How to Use
130
+
131
+ This model is intended to be used with custom inference pipelines.
132
+
133
+ Typical inference steps:
134
+
135
+ 1. Resize input image to model input size
136
+ 2. Normalize pixel values
137
+ 3. Run forward pass
138
+ 4. Apply `argmax` over softmax output to get class IDs
139
+ 5. Visualize lane pixels or overlay segmentation mask
140
+
141
+ ### Example (TensorFlow / Keras)
142
+
143
+ ```python
144
+ import tensorflow as tf
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,
198
+ see the [GitHub repository](https://github.com/yaraeslamm/lane-detection)
199
+
200
+
201
+ ---
202
+
203
+ ## Fine-Tuning
204
+
205
+ Fine-tuning is recommended if:
206
+
207
+ - Using different road environments
208
+ - Working with different camera perspectives
209
+ - Wanting to rebalance lane vs road classes
210
+
211
+ Training scripts support:
212
+
213
+ - Freezing the encoder
214
+ - Full model retraining
215
+ - Custom datasets with RGB masks converted to class IDs
216
+
217
+ ---
218
+
219
+ ## Ethical Considerations
220
+
221
+ This model is intended for **research and educational purposes only**.
222
+
223
+ It should not be used as a sole perception system in safety-critical or real-world autonomous driving applications.
224
+
225
+ ---
226
+
227
+ ## License
228
+
229
+ This model is released under the **Apache 2.0 License**, allowing commercial and research use with attribution.
230
+
231
+ ---
232
+
233
+ ## Author
234
+
235
+ Developed by Yara Elshehawi
236
+ Check out my other work:
237
+ [Portfolio](https://yaraeslamm.github.io)
238
+ [LinkedIn](https://www.linkedin.com/in/yara-eslam-877421212/)
road_segmentation.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ab01dca66dffef4decf41bc5aa3aaf1e4ce069b337b019ab3ae879a9a3cc6db
3
+ size 429445967