Making intersections smarter to reduce driver frustration
By Joe Kessler – Principal Software Developer
This project implements a machine learning-driven traffic simulation for optimizing signal timing in a small city grid. The goal: reduce travel times and improve traffic flow using a Convolutional Neural Network (CNN) and real-time image data from simulated traffic cameras.
- Traffic lights often use simplistic or rigid logic.
- Drivers get stuck at red lights unnecessarily.
- Poor traffic flow increases fuel usage and stress.
Can we do better?
Yes—by simulating intersections that “see” traffic via cameras and respond intelligently.
- 3×3 grid of intersections (9 total)
- Each intersection equipped with 4 cameras (North, South, East, West)
- Real-time image processing to detect traffic and make decisions
- Cars behave like agents with basic GPS routing and 40 MPH max speed
| Component | Language/Tech | Description |
|---|---|---|
Simulator |
Python | Core traffic simulation environment |
CNN Model |
Python (Keras/TensorFlow) | Detects cars and zones from camera images |
Training Data Generator |
C#/WinForms | Creates labeled traffic image data for training |
Traffic Visualizer |
C#/WinForms | Visual display of traffic activity |
CameraWS |
C#/ASP.NET | Simulated camera feed for intersections |
The CNN processes images from simulated cameras to:
- Count vehicles in each lane
- Estimate vehicle distance in three zones: Far, Middle, Near
- Output 9 values per image (3 lanes × 3 distance zones)
model = Sequential()
model.add(Conv2D(32, (5, 5), activation='relu', input_shape=imageShape))
model.add(MaxPooling2D((2, 2)))
model.add(Conv2D(32, (5, 5), activation='relu'))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(100, activation='relu'))
model.add(Dense(9, activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='mean_squared_error', metrics=['accuracy'])
model.fit(trainX, trainY, batch_size=1, epochs=250, verbose=1)Once the CNN is trained, it integrates seamlessly into the simulator:
- Capture images from all 4 directions via
CameraWS. - Predict vehicle presence using CNN.
- Use simple logic to decide if a light should switch.
Example (simplified):
images = capture_image(myconstants.camera_ws_url)
for direction in images:
prediction = model_cnn.predict(images[direction])
traffic_scenario = TrafficScenario(self, prediction, road_lanes, self.global_ctx)
predictions[direction] = traffic_scenario- Same car throughput
- ~50% fewer signal changes
- ~14% lower congestion
- ~11% lower travel times
- Drivers maintain momentum better—fewer “stop-and-go” scenarios
- Intel Core i7-12700K
- 128GB DDR4-3600 RAM
- NVIDIA RTX 3090 Ti (24GB VRAM)
This was originally a video presentation!
For questions/comments, reach out to Joe Kessler.
There’s no complaint box… yet.