Skip to content

satilmiskabasakal0/road-segmentation

Repository files navigation

🛣️ Road Surface Segmentation with U-Net (PyTorch + CUDA)

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.


📌 Features

  • ✅ 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 Architecture

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)

📂 Dataset

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

🚀 Getting Started

1. Clone the repository

git clone https://github.com/satilmiskabasakal0/road-segmentation.git
cd road-segmentation

2. Install dependencies

pip install -r requirements.txt

3. Train the model

python train.py

📈 TensorBoard

tensorboard --logdir=runs

Visualizes:

Training loss over epochs

Predicted masks vs ground truth

4. Run prediction on a sample

python predict.py

📊 Evaluation Metrics

IoU (Intersection over Union) Dice Score

Used to measure segmentation accuracy on binary masks.

🧪 Example Results

5. Run Masking on a Video

python main.py

Real Time Video Results

📁 Project Structure

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

🙋‍♂️ Author

Satılmış Kabasakal – @satilmiskabasakal0

About

U-Net based road surface segmentation trained on KITTI dataset using PyTorch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages