All projects

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

Schematic of a four-way intersection with detection boxes around each vehicle. Counts per approach: west 5, north 3, east 2, south 1. The west approach, with the longest queue, has the green signal.W 5N 3E 2S 1
Schematic, not a recording: vehicles detected on each approach feed the fuzzy rules that set green time.

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()