A deep learning solution for real-time traffic sign classification using convolutional neural networks. This project demonstrates image classification techniques applied to the German Traffic Sign Recognition Benchmark (GTSRB), a challenging real-world dataset used extensively in autonomous driving research.
Traffic sign recognition is a critical component of advanced driver assistance systems and autonomous vehicles. This project implements a CNN-based classifier that achieves over 96% accuracy in identifying 43 different categories of German traffic signs.
The model is trained on the GTSRB dataset, which contains over 50,000 images captured under varying lighting conditions, weather, and viewing angles. Images are preprocessed to a uniform 30x30 pixel resolution before being fed through a multi-layer convolutional architecture that progressively extracts hierarchical visual features.
The final model consists of:
- Input Layer: 30x30x3 RGB images
- First Convolutional Block: 32 filters with 3x3 kernel, ReLU activation, followed by 2x2 max pooling
- Second Convolutional Block: 64 filters with 3x3 kernel, ReLU activation, followed by 2x2 max pooling
- Flatten Layer: Converts 2D feature maps to 1D vector
- Dense Layer: 128 neurons with ReLU activation
- Dropout Layer: 50% dropout rate to prevent overfitting
- Output Layer: 43 neurons with softmax activation for classification
I initially built the model using a single convolutional layer with 32 filters and max pooling with a 3x3 kernel. The output was flattened and fed into 128 hidden units. I also introduced dropout at a rate of 0.5 to address overfitting. While this model compiled successfully, the accuracy was unacceptable at around 5%.
To improve performance, I introduced a second pair of convolutional and max pooling layers. This change led to significantly better results, achieving greater than 96% accuracy with a loss of around 8%.
The first convolutional and max pooling block transforms raw pixels into basic visual features such as edges and simple shapes. The second block builds on these features to detect more complex patterns like corners, curves, and specific shapes that are crucial for distinguishing between traffic signs. This hierarchical feature extraction is fundamental to how CNNs learn to recognize images.
The progression from simple to complex features allows the network to understand traffic signs at multiple levels of abstraction. Low-level features capture edges and color gradients, while higher-level features combine these into recognizable symbols and shapes.
- Python 3.8 or higher
- OpenCV
- scikit-learn
- TensorFlow
git clone https://github.com/yourusername/traffic.git
cd trafficpython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtDownload and extract the GTSRB dataset:
curl -O https://cdn.cs50.net/ai/2023/x/projects/5/gtsrb.zip
unzip gtsrb.zipThis will create a gtsrb directory containing 43 subdirectories (numbered 0 through 42), each representing a traffic sign category.
python traffic.py gtsrbpython traffic.py gtsrb model.h5This will train the model and save it to model.h5 for later use.
The German Traffic Sign Recognition Benchmark (GTSRB) dataset contains:
- 43 classes of traffic signs
- Images of varying sizes (resized to 30x30 for this model)
- Real-world images captured under different lighting and weather conditions
The final model achieves:
- Accuracy: Greater than 98%
- Loss: Approximately 8%
- Institut fur Neuroinformatik for the GTSRB dataset