A deep learning web application for classifying German traffic signs using TensorFlow and Flask. The application can identify 43 different types of traffic signs with high accuracy.
- Features
- Demo
- Project Structure
- Installation
- Usage
- API Documentation
- Deployment
- Configuration
- Model Information
- Contributing
- License
- Real-time Prediction: Upload traffic sign images and get instant predictions
- 43 Traffic Sign Classes: Recognizes 43 different German traffic signs
- High Accuracy: Trained on the German Traffic Sign Recognition Benchmark (GTSRB) dataset
- Responsive UI: Modern, mobile-friendly interface
- RESTful API: JSON API for easy integration
- Health Monitoring: Built-in health check endpoint
- Docker Support: Containerized deployment
- Logging: Comprehensive logging for debugging and monitoring
- Production Ready: Configured for deployment on Heroku, Railway, AWS, etc.
The following chart shows how training and validation accuracy and loss evolve over epochs, illustrating the modelβs convergence and overfitting behavior, along with the final test accuracy obtained on the held-out GTSRB dataset.
The application provides a simple interface to:
- Upload a traffic sign image (PNG, JPG, or JPEG)
- View the prediction with confidence score
- See the classified sign name
Traffic_classifier/
βββ app.py # Main Flask application with logging
βββ config.py # Configuration and environment variables
βββ requirements.txt # Python dependencies
βββ Procfile # Heroku/Railway deployment config
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose configuration
βββ runtime.txt # Python version for deployment
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ signname.csv # Traffic sign class names
βββ traffic-sign.h5 # Trained model (download separately)
β
βββ static/ # Static files
β βββ styles.css # Application styles
β βββ uploads/ # Uploaded images (temporary)
β
βββ templates/ # HTML templates
β βββ index.html # Main page
β
βββ scripts/ # Utility scripts
β βββ sanitize_h5.py
β βββ patch_model_config.py
β
βββ tests/ # Test images
β βββ speed-limit-sign-30-km-h.jpg
β βββ traffic-arrow-sign-only-left.png
β
βββ logs/ # Application logs
βββ app.log # Main log file
- Python 3.10 or higher
- pip (Python package manager)
- Virtual environment (recommended)
- Clone the repository
git clone https://github.com/janeshnanda2005/Traffic_classifier.git
cd Traffic_classifier- Create and activate virtual environment
# Create virtual environment
python3 -m venv env
# Activate on Linux/Mac
source env/bin/activate
# Activate on Windows
env\Scripts\activate- Install dependencies
pip install -r requirements.txt-
Download the model
- Ensure
traffic-sign.h5is in the project root - The model file is not included in git due to size (>100MB)
- Ensure
-
Run the application
python app.pyThe application will be available at http://localhost:5000
- Open your browser and navigate to
http://localhost:5000 - Click on the upload area or drag and drop a traffic sign image
- Click "Classify Image"
- View the prediction result with confidence score
POST /predict
Upload an image file to get a prediction.
Request:
- Method: POST
- Content-Type: multipart/form-data
- Body: Form data with 'file' field containing the image
Example using curl:
curl -X POST -F "file=@path/to/traffic-sign.jpg" http://localhost:5000/predictResponse:
{
"success": true,
"predicted_class": 1,
"sign_name": "Speed limit (30km/h)",
"confidence": 0.9876,
"image_data": "base64_encoded_image...",
"timestamp": "2025-11-08T10:30:45"
}GET /health
Check the application health status.
Response:
{
"status": "healthy",
"model_loaded": true,
"csv_loaded": true,
"timestamp": "2025-11-08T10:30:45"
}| Variable | Default | Description |
|---|---|---|
FLASK_DEBUG |
False |
Enable Flask debug mode |
PORT |
5000 |
Server port |
HOST |
0.0.0.0 |
Server host |
MODEL_PATH |
traffic-sign.h5 |
Path to model file |
SIGNNAME_CSV |
signname.csv |
Path to sign names CSV |
UPLOAD_FOLDER |
static/uploads |
Upload directory |
MAX_CONTENT_LENGTH |
16777216 |
Max upload size (16MB) |
LOG_LEVEL |
INFO |
Logging level |
LOG_FILE |
logs/app.log |
Log file path |
EAGER_LOAD_MODEL |
False |
Load model at startup |
CORS_ENABLED |
False |
Enable CORS |
FLASK_DEBUG=false
PORT=5000
LOG_LEVEL=INFO
EAGER_LOAD_MODEL=true
MODEL_PATH=traffic-sign.h5- Total Classes: 43 traffic sign types
- Training Images: 34,799
- Validation Images: 4,410
- Test Images: 12,630
- Image Size: 32x32 pixels (RGB)
- Pre-trained model based on Convolutional Neural Networks
- Input shape: (32, 32, 3)
- Output: 43 classes with softmax activation
- Optimized for accuracy and inference speed
The model can identify 43 classes including:
- Speed limits (20, 30, 50, 60, 70, 80, 100, 120 km/h)
- No passing, No entry, Stop, Yield
- Priority road, Keep right/left
- Various warning signs (curves, bumps, animals, etc.)
- And more...
See signname.csv for the complete list.
export FLASK_DEBUG=true
export LOG_LEVEL=DEBUG
python app.py# Test with sample images
python -c "
from app import process_image
from PIL import Image
# Test prediction
with open('tests/speed-limit-sign-30-km-h.jpg', 'rb') as f:
result = process_image(f)
print(result)
"app.py: Main Flask application with routes and error handlersconfig.py: Configuration managementtemplates/index.html: Frontend UIstatic/styles.css: Responsive CSS styling
The application uses Python's logging module with:
- Console output for development
- File logging to
logs/app.log - Configurable log levels (DEBUG, INFO, WARNING, ERROR)
- Structured log format with timestamps
View logs:
tail -f logs/app.log- File type validation (only PNG, JPG, JPEG allowed)
- File size limits (16MB max)
- Input sanitization
- Error handling without exposing sensitive information
- CORS configuration for production
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Janesh Nanda - janeshnanda2005
- German Traffic Sign Recognition Benchmark (GTSRB) dataset
- TensorFlow and Keras teams
- Flask framework contributors
For issues and questions:
- Create an issue on GitHub
- Contact: [janeshnanda@gmail.com]
Made with β€οΈ using Flask and TensorFlow