Smart Traffic Management System An AI-based traffic management system for optimizing signal timings and reducing congestion in urban areas, specially designed for Indian conditions.
Overview The Smart Traffic Management System uses computer vision, reinforcement learning, and large language models to analyze real-time traffic data from cameras and sensors to predict and mitigate bottlenecks. It is specifically adapted for Indian traffic conditions, including detection of vehicles, humans, animals
Object Detection: Identifies vehicles, pedestrians, animals, and other road users using YOLOv8 Pothole Detection: Detects and analyzes road surface conditions Traffic Sign Recognition: Identifies Indian traffic signs and speed limits Weather Analysis: Assesses weather conditions affecting visibility and road safety Railway Crossing Monitoring: Detects railway crossings and presence of trains Traffic Optimization: Uses reinforcement learning to optimize traffic signal timings LLM-powered Insights: Generates natural language insights about traffic conditions User Authentication: Secure login/registration system with JWT-based authentication Role-based Access Control: Different permissions for users and administrators Responsive Web Interface: User-friendly dashboard for traffic monitoring System Architecture The system consists of three main components:
Python FastAPI Backend - Core detection and analysis services Node.js Authentication Server - User authentication and session management HTML/CSS/JS Frontend - Web interface for users Project Structure The project is organized into separate frontend and backend components:
stms-backend/ ├── auth-server.js # Node.js Authentication Server ├── schema.sql # Database Schema ├── package.json # Node.js Dependencies ├── backend/ # Backend code │ ├── api/ # FastAPI endpoints │ │ ├── main.py │ │ ├── auth.py # Authentication middleware │ │ └── init.py │ ├── auth-bridge.js # Bridge between Auth and Python backend │ ├── config.js # Configuration for servers │ ├── detectors/ # Detection modules │ │ ├── base_detector.py │ │ ├── object_detector.py │ │ ├── pothole_detector.py │ │ ├── railway_crossing_detector.py │ │ ├── traffic_sign_detector.py │ │ ├── weather_detector.py │ │ └── init.py │ ├── llm/ # Language model integration │ ├── models/ # Data models and schemas │ ├── optimization/ # Traffic signal optimization │ └── utils/ # Utility functions ├── frontend/ # Frontend code │ ├── dashboard.html # Dashboard interface │ ├── index.html # Main landing page │ ├── login.html # User login page │ ├── profile.html # User profile page │ ├── register.html # User registration page │ ├── assets/ # Images and media │ ├── css/ # Stylesheets │ │ ├── auth.css # Authentication styling │ │ └── styles.css # Main styling │ ├── js/ # JavaScript │ │ ├── auth.js # Authentication logic │ │ └── main.js # Main application logic │ ├── css/ # Stylesheets │ ├── js/ # JavaScript code │ └── index.html # Main HTML file ├── ai_models/ # Trained ML models │ └── indian_traffic_sign_model.pth ├── snapshots/ # Detection snapshots ├── demo_railway_crossing.ipynb # Demo notebook └── run.py # Main application entry point Features Object Detection: Detects vehicles, humans, and animals in traffic scenes Road Condition Analysis: Detects potholes and other road damages Weather Detection: Identifies weather conditions and their impact on traffic Traffic Signal Optimization: Uses reinforcement learning to optimize signal timings Traffic Sign Detection: Identifies traffic signs specific to Indian roads Railway Crossing Detection: Detects railway crossings and trains intersecting with roads LLM-powered Traffic Insights: Provides intelligent analysis and recommendations Detector Modules The detection functionality is organized into separate modules:
base_detector.py: Abstract base class for all detectors object_detector.py: General object detection using YOLO pothole_detector.py: Road condition and pothole detection railway_crossing_detector.py: Railway crossing and train detection traffic_sign_detector.py: Indian traffic sign detection weather_detector.py: Weather condition detection Installation and Setup Prerequisites Python 3.8+ Node.js 14+ YOLOv8 Installation Clone the repository:
git clone https://github.com/yourusername/stms-backend.git cd stms-backend Install Python dependencies:
pip install -r requirements.txt Install Node.js dependencies (for auth server):
npm install Download pre-trained models:
python scripts/setup_traffic_sign_detection.py Running the System Combined Web Server (Recommended) Run the combined server that integrates both frontend and backend:
python run_stms_server.py The application will be available at http://localhost:8001
Running Components Separately Start the authentication server:
node auth-server.js Start the backend API:
python run.py Serve the frontend (if needed separately):
python -m http.server -d frontend 8000 API Endpoints /detect/objects: Detect objects in traffic scenes /detect/potholes: Detect potholes and road damages /detect/weather: Detect weather conditions /detect/traffic_signs: Detect traffic signs /detect/railway_crossings: Detect railway crossings and trains /optimize/signals: Optimize traffic signal timings /insights: Generate traffic insights using LLM Getting Started Prerequisites Python 3.8+ PyTorch OpenCV FastAPI Ultralytics (YOLO) Other dependencies in requirements.txt Installation Clone the repository:
git clone https://github.com/dillikumar2007/stms-backend.git cd stms-backend Install Python dependencies:
pip install -r requirements.txt Install Node.js dependencies:
npm install Set up the database:
psql -U postgres -d your_database_name -f schema.sql Configure environment variables:
cp .env.example .env
Run the authentication server:
node auth-server.js Run the backend API:
python run.py Serve the frontend:
npx http-server frontend -p 5000 Access the application:
http://localhost:5000 Demo Check out the demo_railway_crossing.ipynb notebook for a demonstration of the system's capabilities, including the new railway crossing detection functionality.
Future Enhancements Deployment to edge devices for real-time processing Integration with traffic signal hardware Expansion of traffic sign detection to more sign types Larger-scale reinforcement learning training Mobile app for traffic operators