Back to Case Studies
publishedR&DOpenAIReinforcement LearningComputer VisionPythonPyTorch

AI Self-Driving Race Car

Adapted Deep Q-Network (DQN) solving OpenAI Gym CarRacing-v0 with a 905.38 average score across 100 consecutive episodes. Published at IEEE IWSSIP.

Developed in 2020 at the Intelligent Systems lab at Instituto Superior Técnico (IST) in Lisbon, this research project investigated how to train an autonomous racing agent from raw pixel inputs on constrained consumer hardware, resulting in a peer-reviewed publication at IEEE IWSSIP.

Objective: Train a Deep Reinforcement Learning agent to solve the continuous-control CarRacing-v0 environment from raw 96x96 RGB frames—learning steering, acceleration, and braking purely from reward signals without prior physics models.

Project Showcase

Training Progression

Timelapse of the DQN agent across training episodes, progressing from initial random exploration to stable cornering and apex clipping.

Evaluation Run (900+ Score)

The converged policy navigating unseen procedural tracks, maintaining an average score above 905 across 100 consecutive evaluation episodes.

Technical Methodology

We designed an Adapted Deep Q-Network (DQN) tailored to converge rapidly on a single mobile GPU (NVIDIA GTX 1050 Ti) by reducing input dimensionality and shaping the reward signal:

  1. Temporal State Representation: Stacking 4 consecutive preprocessed 96x96 grayscale frames (96x96x4) so the convolutional layers can infer velocity, angular momentum, and acceleration directly from pixel deltas.
  2. Reward Shaping: Augmenting the environment reward to penalize off-track grass contact and excessive braking while rewarding sustained forward velocity along the track centerline.

Benchmark Results

OpenAI's CarRacing-v0 benchmark is defined as solved when an agent achieves an average score of 900.0 over 100 consecutive evaluation episodes. Our adapted architecture exceeded this threshold with low variance:

Metric
Base DQN
Adapted DQN (Our Work)
Convergence Speed
Slow / Unstable
Fast / Stable
Peak Score
~600
920+
100-Episode Test Avg
< 400
905.38 ± 23.82

Architecture & Input Optimization

Training deep reinforcement learning policies from pixel inputs is sample-inefficient. To converge within hardware memory limits, we stripped redundant visual entropy before the frames entered the neural network.

1. Frame Preprocessing Pipeline

Raw 96x96x3 RGB observations were transformed through a four-stage pipeline:

  • Grayscale Reduction: Collapsing 3 RGB channels into a single luminance channel (96x96x1).
  • Background Binarization: Mapping green grass pixels to uniform white so road boundaries form high-contrast edges for convolutional filters.
  • Telemetry Masking: Masking the bottom HUD score bar with a black rectangle to prevent the CNN from overfitting to rendered score digits.
  • 4-Frame Temporal Stack: Concatenating the 4 most recent frames into a 96x96x4 tensor to encode velocity and trajectory.

2. Action Space Discretization

The native CarRacing-v0 environment exposes a 3-dimensional continuous action space (steering $\in [-1, 1]$, gas $\in [0, 1]$, brake $\in [0, 1]$). Rather than training an actor-critic policy over continuous bounds, we discretized the control surface into 5 orthogonal actions:

  1. Steer Left
  2. Steer Right
  3. Accelerate
  4. Brake
  5. Coast (No-Op)

Discretizing the action space eliminated unstable policy gradients during early exploration and allowed standard Q-value maximization with experience replay to converge in a fraction of the episodes.

3. Compact 3-Layer CNN Topology

The Q-network maps the 96x96x4 input tensor to the 5 discrete action values using a lightweight convolutional backbone:

  • Conv Layer 1: 8 filters (7x7 kernel, stride 4) capturing coarse road geometry.
  • Conv Layer 2: 16 filters (3x3 kernel, stride 1) with 2x2 max-pooling to isolate track borders and corner curvature.
  • Dense Head: A 400-unit fully connected layer with ReLU activation projecting spatial features to the 5 Q-value outputs.
Instituto Superior Técnico
Published Research

Optimizing Agent Training with Deep Q-Learning on a Self-Driving Reinforcement Learning Environment

ieee

Publisher

IEEE

Venue

IWSSIP (Lisbon, Portugal)

Resources


This research at Instituto Superior Técnico shaped how we approach AI engineering today: before scaling compute or adding model complexity, constrain the state space, clean the input signal, and formulate a deterministic objective.

— Pedro

Founder & Principal Engineer