LaneKeeper is a self-driving car simulation built in Python.
It combines:
- Pyglet for rendering & simulation.
- Neural Networks for processing sensor data and controlling the car.
- Genetic Algorithm for training and optimizing the neural network weights.
- Car simulation on custom tracks.
- Neural network with 5 inputs, 4 hidden layers, 2 outputs.
- Genetic algorithm with selection, crossover, and mutation.
- Training system that improves driving across generations.
- Saves the best weights in
brain.jsonfor reuse on any track.
│── images_/ # Assets (track, cars, UI, etc.)
│── brain.json # Saved best weights (trained genes)
│── canvas.py # Drawing / rendering helpers
│── car.py # Car object & physics
│── evolution.py # Genetic algorithm logic
│── hud.py # HUD / stats display
│── network.py # Neural network implementation
│── storage.py # Save / load utilities
│── testdriver.py # Run a car using saved brain.json
│── track.py # Track & checkpoints
│── training.py # Training loop (main entry)
│── requirements.txt # Python dependencies
│── README.md
Clone the repository and install dependencies:
git clone https://github.com/yousifnimah/Self-Driving-Car-Simulation-with-Neural-Networks-Genetic-Algorithm
cd Self-Driving-Car-Simulation-with-Neural-Networks-Genetic-Algorithm
pip install -r requirements.txtRun training mode (cars evolve using GA):
python training.pyAfter training, the best weights are saved to brain.json.
You can test the saved model with:
python testdriver.py- More advanced tracks & obstacles.
- Deep Reinforcement Learning integration.
- Multi-agent driving.
#Python #AI #NeuralNetworks #GeneticAlgorithm #Pyglet #SelfDrivingCar
