Introduction
Traffic signs are crucial for ensuring road safety and guiding drivers. With self-driving cars and intelligent transportation systems becoming more common, automating the recognition of traffic signs is vital. This project, “Traffic Sign Classification,” leverages deep learning to identify traffic signs from images, laying the groundwork for safer roadways.
Want to explore this project hands-on? You can access the complete implementation on Google Colab. Click the link below to get started:
https://colab.research.google.com/drive/1bFTRr0ULw53CXL0uUGhGHIV3taU4p8cs?usp=sharing
Dataset Overview
The [mention dataset name, e.g., German Traffic Sign Recognition Benchmark (GTSRB)] dataset was used for this project. It contains thousands of labeled images of traffic signs in different categories.
Loading the Dataset
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# Example: Load dataset and visualize
data = pd.read_csv('path/to/traffic_sign_data.csv')
print(f"Number of classes: {len(data['class'].unique())}")
data.head()
# Display an example image
plt.imshow(plt.imread('path/to/example_image.png'))
plt.title("Example Traffic Sign")
plt.show()
Data Preprocessing
To ensure high model performance, the dataset was preprocessed with techniques like normalization, resizing, and data augmentation.
Normalizing and Resizing Images
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# Normalize image data
X = X / 255.0
# Resize images
X_resized = np.array([cv2.resize(img, (32, 32)) for img in X])
# Train-test split
X_train, X_test, y_train, y_test = train_test_split(X_resized, y, test_size=0.2, random_state=42)
# Convert labels to categorical
y_train = to_categorical(y_train, num_classes=43)
y_test = to_categorical(y_test, num_classes=43)
Data Augmentation
datagen = ImageDataGenerator(
rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.1
)
datagen.fit(X_train)
Model Architecture
A convolutional neural network (CNN) was employed for traffic sign classification. Below is an example of the model architecture.
Building the CNN Model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout
model = Sequential([
Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
MaxPooling2D((2, 2)),
Dropout(0.25),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D((2, 2)),
Dropout(0.25),
Flatten(),
Dense(128, activation='relu'),
Dropout(0.5),
Dense(43, activation='softmax') # Number of classes
])
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()
Training the Model
The model was trained over multiple epochs to minimize loss and improve accuracy.
Training Code
history = model.fit(
datagen.flow(X_train, y_train, batch_size=32),
epochs=20,
validation_data=(X_test, y_test)
)
# Plotting the training history
plt.plot(history.history['accuracy'], label='Train Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.legend()
plt.title('Model Accuracy')
plt.show()
Results
The model achieved a test accuracy of [insert accuracy]. Below is the confusion matrix visualizing the model’s performance.
Visualizing Predictions
from sklearn.metrics import classification_report, confusion_matrix
y_pred = model.predict(X_test)
y_pred_classes = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_test, axis=1)
print(classification_report(y_true, y_pred_classes))
# Confusion matrix
conf_matrix = confusion_matrix(y_true, y_pred_classes)
plt.matshow(conf_matrix, cmap='coolwarm')
plt.title('Confusion Matrix')
plt.show()
Applications
This project has real-world applications in:
- Autonomous Vehicles: Recognizing traffic signs in real time.
- Driver Assistance Systems: Alerting drivers to upcoming signs.
- Urban Traffic Management: Cataloging and monitoring traffic signs.
Conclusion
The “Traffic Sign Classification” project demonstrates the power of deep learning in solving critical road safety challenges. Future improvements could include real-time detection and recognition systems to further enhance its robustness.