Trained an AI playing Sonic the Hedgehog by Deep Reinforcement Learning model:
Asynchronous Advantage Actor-Critic(A3C) with LSTM cell using tensorflow2-keras API
- Clone the repository:
https://github.com/Chang-Chia-Chi/Sonic-the-Hedgehog-A3C-LSTM-tensorflow2.git
- Run
pip3 install -r requirements.txt
to install packages required. - Sonic 1, 2 and 3 & Knuckles ROMs are available on Steam:
- Once you buy any of games, use script
python -m retro.import.sega_classics
. You'll be asked to type
Steam username, password and Guard code: - After installation, use script
python -m retro.import <path to steam folder>
- For more detail please follow this link
- Open
parser.py
, change argements of--game and --state
to which Sonic game, Zone and Act you want to train.
You could find all levels in these two links: -sonic-train.csv, -sonic-validation.csv - run
python train.py
to start training. - By default, it'll save model weights, model performance in distance, and video (.bk2) every 10 episodes.
- model and training setting parameters are in
parser.py
. - If you want to load pre-trained weights, open
train.py
and setpretrain=True
.`
- Open test.py, change
game
andstate
to level you want. - If you don't want to record gameplay, set
record=False
- Run
python test.py
P.S. Uploaded pre-trained weights are trained with Impala CNN model
- python == 3.7
- tensorflow == 2.3.0
- Run script
python3 -m retro.scripts.playback_movie <Record file name>.bk2 <output file name>.mp4
- For more detail please follow this link