Traffic System Optimization
An R-CNN model counts vehicles in live traffic footage, and fuzzy logic turns those counts into signal timing.
Built with PyTorch, Streamlit, Fuzzy logic
How it works
An R-CNN model detects vehicle density in live traffic footage, feeding fuzzy logic rules that propose signal timing adjustments.
A custom Streamlit interface lets you watch detection and the fuzzy reasoning happen in real time.
Specs
- Detection model
- R-CNN (PyTorch)
- Input
- Live traffic video stream
- Decision layer
- Fuzzy inference on density
- Visualization
- Streamlit dashboard
Vehicle detection
detect.py
import torch
from torchvision.models.detection import fasterrcnn_resnet50_fpn
model = fasterrcnn_resnet50_fpn(pretrained=True)
model.eval()
def detect_vehicles(frame, threshold=0.7):
tensor = to_tensor(frame).unsqueeze(0)
with torch.no_grad():
preds = model(tensor)[0]
boxes = preds["boxes"]
scores = preds["scores"]
keep = scores > threshold
return boxes[keep].tolist()