Skip to content

Self-Driving Car Simulation leverages neural networks and the NEAT algorithm to train autonomous vehicles on random roads. Built with Python and Pygame, it showcases AI-driven learning for efficient navigation and decision-making.

Notifications You must be signed in to change notification settings

Taaran18/Self-Driven-Car

Repository files navigation

Self-Driven Car using NEAT 🚗🧠

This project is a simulation of self-driving cars controlled by neural networks, implemented using the Python programming language and the Pygame library for graphics rendering. The cars navigate through a randomly generated road, and their neural networks are trained using the NEAT (NeuroEvolution of Augmenting Topologies) algorithm to learn how to drive successfully.

Features ✨

  • Simulation of self-driving cars controlled by neural networks
  • Randomly generated road with varying curvatures and slopes
  • Neural network training using the NEAT algorithm
  • Visualization of the neural network structure and connections
  • Real-time display of car positions, velocities, and sensor inputs

Neural Network Architecture 🧠

The neural network architecture used in this simulation is a feed-forward network with the following structure:

  • Input Layer: 9 nodes
    • 8 nodes representing the distances from the car to the road boundaries in 8 different directions
    • 1 node representing the car's current velocity
  • Hidden Layer: Variable number of nodes, determined by the NEAT algorithm
  • Output Layer: 4 nodes
    • 1 node for accelerating
    • 1 node for braking
    • 1 node for turning left
    • 1 node for turning right

The neural network takes the sensor inputs and the car's velocity as input and outputs four values representing the actions to be taken (accelerate, brake, turn left, or turn right).

Neural Network Calculation 🧮

The neural network is calculated using the following steps:

  1. The sensor inputs and the car's velocity are fed into the input layer of the neural network.
  2. The input values are propagated through the hidden layer(s) using the weights and biases determined by the NEAT algorithm.
  3. The outputs of the hidden layer(s) are propagated to the output layer, producing four output values.
  4. The output values are interpreted as follows:
    • The accelerate output determines whether the car should accelerate or not.
    • The brake output determines whether the car should brake or not.
    • The turn left and turn right outputs determine the direction the car should turn.
  5. The car's actions (accelerate, brake, turn left, or turn right) are executed based on the output values.

The neural network is trained over multiple generations using the NEAT algorithm, which evolves the network's topology and weights to optimize the car's performance on the road.

Requirements 📋

Installation 🚀

  1. Clone the repository or download the source code.
git clone https://github.com/Taaran18/Self-Driven-Car.git
  1. Install the required dependencies using pip:
pip install pygame numpy scipy neat-python

Usage 🏃‍♂️

  1. Navigate to the project directory.
cd self-driven-car
  1. Run the main script:
python main.py

The simulation will start, and you can observe the self-driving cars navigating through the road. The neural networks will be trained over multiple generations, and the best-performing car's neural network structure will be visualized.

Configuration ⚙️

The simulation parameters and neural network configurations can be modified in the config_variables.py and config_file.txt files, respectively. Refer to the comments in these files for more information on the available settings.

Contributing 🤝

Contributions to this project are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request.

Project Contributors

License 📄

This project is licensed under the MIT License.

Acknowledgments 🙏

This project was inspired by various neural network car simulations and tutorials available online. Special thanks to the creators of the Pygame library, NumPy, SciPy, and NEAT-Python for providing the necessary tools and libraries.

Support 🌟

If you find this project useful, please consider giving it a ⭐️ on GitHub!

About

Self-Driving Car Simulation leverages neural networks and the NEAT algorithm to train autonomous vehicles on random roads. Built with Python and Pygame, it showcases AI-driven learning for efficient navigation and decision-making.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages