As part of a master project, a functional snake agent was developed with the help of Double Q-learning, PyTorch and a CNN.
The Blogpost (german) of this project can be found here.
python3 -m venv /path/to/new/virtual/environment
source <venv>/bin/activate
(windows) C:\> <venv>\Scripts\activate.bat
you should see a (venv) in front of your command promptpip install -r requirements.txt
To start the learning process for the Snake,
python main.py
This starts the double Q-learning and logs the training data to the checkpoints
folder.
You can also train an existing model by specifying a checkpoint in the main.py
class. e.g current_checkpoint = Path(''checkpoints/timestamp/name_of_the_checkpoint.chkpt')
GPU will automatically be used if available.
To evaluate a trained Snake-model use,
python replay.py
This starts a window in which the Snake-agent "plays" a trained model. No training will take place. To evaluate a specific model, simply change the save_dir in replay.py
.
E.g checkpoint = Path('checkpoints/timestamp/name_of_the_checkpoint.chkpt')
A pretrained model can be found in the src/pretrained_checkpoint
folder. The model was trained for approx. 24 hours. A Google Cloud VM instance was used as the training hardware:
The pre-trained model achieved the following scores:
avg. Score: 12
MetricLogger
that helps track training/evaluation performance.