Trinetra is a full-stack, real-time AI prototype designed to prevent crowd-related tragedies.
It analyzes live video feeds using an optimized deep learning model to understand complex crowd dynamics.
The system calculates a multi-factor Chaos Score and broadcasts it to a command dashboard. When risk remains high, alerts are dispatched to a dedicated, mobile-first app for on-ground volunteer teams.
Traditional crowd surveillance is reactive. Authorities detect danger only when it’s too late. Simple metrics like crowd density miss the dynamic risks of:
- 🚶♂️ Flow: Chaotic crowd movement
- 🚀 Surge: Rapid influx of people
These are primary triggers for stampedes.
Trinetra calculates a proactive Chaos Score based on:
| Metric | Description |
|---|---|
| D (Density) | How crowded is the space? |
| F (Flow) | How chaotic is the movement? |
| S (Surge) | How rapidly is the crowd growing? |
When the score remains high, Trinetra dispatches alerts to volunteers—turning AI predictions into real-time action.
| Metric | Before | After |
|---|---|---|
| Inference Time | ~40 sec/frame | ~0.9 sec/frame |
| Backend Design | Single-threaded | Multi-process |
| Model Runtime | PyTorch | ONNX Runtime |
| Alert Latency | Delayed / Blocking | Near Real-Time |
Trinetra uses a decoupled, multi-process architecture to ensure real-time performance:
- Reads frames from a video source (
crowd_video.mp4) - Applies pre-checks (blur detection)
- Adds frames to a shared queue
- Pulls frames from queue
- Uses ONNX Runtime to analyze crowd
- Calculates D_norm, F_norm, S_norm → Chaos Score
- Passes results to output queue
- Flask-SocketIO server broadcasts data via WebSockets
- Receives dispatch commands from dashboard
- Tracks volunteer status
- React frontend displaying live metrics
- Calculates 10-second average of Chaos Score
- Sends dispatch command when high risk is sustained
- Mobile-first React app for on-ground teams
- Displays alerts in real-time with location and score
| Technology | Version |
|---|---|
| Python | 3.8 |
| ONNX Runtime | 1.15.1 |
| Flask-SocketIO | 5.3.6 |
| OpenCV | 4.8.0 |
| NumPy / SciPy | 1.24.3 / 1.10.1 |
| Technology | Version |
|---|---|
| React | 18.2.0 |
| Socket.IO Client | 4.7.2 |
| Tailwind CSS | 3.3.3 |
| Recharts | 2.8.0 |
| Model | Format |
|---|---|
| P2PNet | ONNX |
-
Install Anaconda / Miniconda
-
Create and activate the environment
conda create --name onnx_env python=3.8 -y conda activate onnx_env
-
Install Python Dependencies
pip install onnx onnxruntime opencv-python numpy scipy psutil Flask Flask-Cors Flask-SocketIO python-socketio gevent-websocket waitress
-
Export the AI Model (One-Time Step)
-
Install legacy torch libraries needed for export:
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
-
Run the
export_to_onnx.pyscript to generate thep2pnet.onnxfile.
-
-
Install Node.js (LTS version)
-
Install
servegloballynpm install -g serve
-
Set up the Main Dashboard
# Navigate to the trinetra-dashboard folder cd path/to/trinetra-dashboard npm install npm run build
-
Set up the Volunteer App
# Navigate to the trinetra-volunteer-app folder cd path/to/trinetra-volunteer-app npm install npm run build
-
v1.3: Full-Stack WebSocket Integration
- Two-way communication with volunteers
- Live tracking of connected volunteers
- Complete dispatch system from dashboard to volunteer app
-
v1.2: ONNX Performance Migration
- Converted AI model to ONNX
-
30x reduction in inference latency (~1.05s)
-
v1.1: Multi-Process Architecture & Quantization
- Parallel, non-blocking backend
- PyTorch Dynamic Quantization reduced latency to ~9–12 seconds
-
v1.0: Core Engine & Initial Prototype
- Full D-F-S Chaos Score logic
- Integrated P2PNet AI model
-
v0.1: Concept & Formula
- Defined initial Chaos Score formula
Thank you for checking out Trinetra!
For questions or contributions, please open an issue or pull request.