This project performs semantic segmentation of road surfaces from camera images using a custom-built U-Net architecture implemented in PyTorch. It is designed for educational and experimental purposes in computer vision and autonomous driving systems.
- ✅ Custom U-Net implementation in PyTorch
- ✅ Supports GPU acceleration with CUDA
- ✅ Binary road segmentation (road vs non-road)
- ✅ Evaluation with IoU and Dice Score
- ✅ TensorBoard support for training visualization
- ✅ KITTI Road Dataset compatibility
U-Net is a fully convolutional neural network designed for image segmentation. It consists of:
- Encoder (contracting path): captures semantic context using convolution and pooling
- Decoder (expanding path): enables precise localization using transposed convolutions
- Skip connections: bridge encoder and decoder layers to preserve spatial information
In this project:
- Input: RGB image (3 channels)
- Output: Binary mask (1 channel)
- Loss:
BCEWithLogitsLoss
(optionally Dice Loss) - Optimizer:
Adam
- Image size: 256x256 (resized)
This project uses the KITTI Road Benchmark Dataset.
Due to file size limits, the dataset is not included in this repository.
Download the base kit
git clone https://github.com/satilmiskabasakal0/road-segmentation.git
cd road-segmentation
pip install -r requirements.txt
python train.py
tensorboard --logdir=runs
Training loss over epochs
Predicted masks vs ground truth
python predict.py
IoU (Intersection over Union) Dice Score
Used to measure segmentation accuracy on binary masks.
python main.py
road_segmentation_project/
├── data_road/
│ ├── training/
│ │ ├── image_2/
│ │ └── gt_image_2/
│ │
│ └── testing/
│ └── image_2/
├── models/
│ └── unet.py # U-Net model implementation
├── dataset.py # Custom dataset class
├── train.py # Training script
├── predict.py # Inference and visualization
├── main.py # Running Unet on a Real-Time Video
├── sample-dash-cam.mp4 # A random dash cam video for testing from youtube
├── runs/ # TensorBoard logs
├── requirements.txt
└── README.md
Satılmış Kabasakal – @satilmiskabasakal0