SmartLight AI is a full-stack AI-based traffic signal control system that dynamically optimizes traffic flow using real-time vehicle detection and Deep Reinforcement Learning.
This project uses:
- YOLOv8m for real-time vehicle detection
- Deep Q-Network (DQN) for adaptive signal decision making
- FastAPI backend with WebSocket communication
- React + Tailwind frontend dashboard
- Real-time traffic visualization
Traditional traffic lights operate on fixed timers.
SmartLight AI:
- Detects vehicles per lane using YOLO
- Builds a traffic state vector
- Uses Deep Q-Network to select optimal signal
- Dynamically adjusts green time
- Streams real-time updates to dashboard
- Supports manual override and emergency mode
Video Stream ↓ YOLOv8m Detection Service ↓ Lane State Manager ↓ DQN Agent (Decision Engine) ↓ Signal Manager ↓ FastAPI WebSocket Server ↓ React Dashboard
- FastAPI
- PyTorch
- Ultralytics YOLOv8m
- OpenCV
- WebSockets (native FastAPI)
- React
- Tailwind CSS
- Chart.js
- WebSocket Client
SmartLightAI/ │ ├── backend/ │ ├── main.py │ ├── services/ │ │ ├── yolo_service.py │ │ ├── dqn_agent.py │ │ ├── signal_manager.py │ │ ├── state_manager.py │ │ │ ├── models/ │ │ ├── yolov8m.pt │ │ └── dqn_model.pth │ │ │ └── core/ │ └── config.py │ ├── frontend/ │ ├── src/ │ │ ├── components/ │ │ │ ├── Dashboard.jsx │ │ │ ├── LaneCard.jsx │ │ │ ├── SignalLight.jsx │ │ │ └── TrafficChart.jsx │ │ │ └── package.json │ └── README.md
conda activate smartlight
Installed:
- torch
- ultralytics
- opencv-python
- numpy
Install additional backend requirements:
pip install fastapi uvicorn
Install Node.js (LTS version).
Then:
cd frontend npm install npm run dev
cd backend uvicorn main:app --reload
Backend runs at:
cd frontend npm run dev
Frontend runs at:
[N_count, S_count, E_count, W_count, current_green_index]
0 → North (N) 1 → South (S) 2 → East (E) 3 → West (W)
reward = - total_waiting_vehicles
- Real-time YOLO vehicle detection
- Deep Reinforcement Learning signal optimization
- WebSocket live updates
- Emergency vehicle override
- Manual override controls
- AI ON/OFF toggle
- Performance metrics dashboard
- Dynamic green time calculation
- Scalable architecture
- YOLOv8m provides higher accuracy but slower inference on CPU.
- Use YOLOv8n for faster performance if required.
- Process every 3rd or 5th frame for optimization.
If emergency vehicle detected:
- Corresponding lane gets priority
- DQN temporarily paused
- After emergency clearance, AI resumes
- Live vehicle counts per lane
- Signal status indicators
- Countdown timers
- Traffic density chart
- AI performance metrics
- Multi-intersection coordination
- Cloud deployment
- CCTV live feed integration
- Model training dashboard
- Database logging (PostgreSQL / MongoDB)
- Multi-agent reinforcement learning
- Smart City Traffic Optimization
- AI-based Infrastructure Automation
- Research in Reinforcement Learning
- Final Year Engineering Project
✔ Professional full-stack architecture
✔ Real-time AI decision system
✔ Modular and scalable
✔ Resume-ready AI project
This project is developed for educational and research purposes.