Skip to content

Thibault-GAREL/AI_driving_DQN_version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Driving AI with Deep Q-learning

Python PyTorch Numpy Pygame

License
Contributions

gif logo : driving AI

📝 Project Description

This project showcases an AI that learns to drive a car in my 2D driving environment using the deep Q-learning algorithm. No hardcoded pathfinding — the agent improves by trial, error, and reward-based learning. 🧠📈


🚀 Features

🤖 Uses Deep Q-Learning with experience replay and epsilon-greedy exploration

🧱 Neural network approximates Q-values for discrete actions (e.g., accelerate, turn left/right)

Example Outputs

Here is an image of what it looks like :

Image_cars

📝 Notes & Observations

⏳ Training is unstable at first — the car often spins out or crashes quickly — but over time, it learns to stabilize, turn properly, and sometimes follow simple roads or avoid walls.

🎛️ Hyperparameters (learning rate, epsilon decay, reward shaping) have a huge impact on learning performance.

Here, we can see that over 100 steps, the best path have been found (in just more than 5 min).

It is more hesitant for the borrowed path but adapts better to different circuits than Genetic algorithm such as AI_driving_genetic_version !


⚙️ How it works

🎮 The AI controls a car in a Pygame environment with basic physics and obstacles.

🧠 It uses a Deep Q-Network to estimate the best action to take from any given state.

🧾 Inputs include distance to next checkpoint, velocity, distance to obstacles, and relative angles to next checkpoint.

🎯 Rewards are given based on life time, distance to the next checkpoint, avoiding collisions, velocity to encourage speed and reaching checkpoints.


📂 Repository structure

├── Images/                     # Images for the README
│
├── dqn_model.pth               # Saved model checkpoint
│
├── ia.py                       # AI logic
├── main.py                     # Project entry point
├── drive.py                    # Driving game implementation
│
├── LICENSE                     # Project license
├── README.md                   # Main documentation

💻 Run it on Your PC

Clone the repository and install dependencies:

git clone https://github.com/Thibault-GAREL/AI_driving_DQN_version.git
cd AI_driving_DQN_version

python -m venv .venv #if you don't have a virtual environnement
source .venv/bin/activate   # Linux / macOS
.venv\Scripts\activate      # Windows

pip install torch numpy pygame

python main.py

📖 Inspiration / Sources

I code it without any help 😆 !

Code created by me 😎, Thibault GAREL - Github

About

A Deep Q-Learning AI learning to drive

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages