Playing Atari Breakout with a DQN Agent, using PyTorch. This implementation is based on DeepMind 2013 paper on Deep Reinforcement Learning to play Atari games.
The DQN network architecture consists of:
- 2 convolutional layers for feature extraction
- 2 fully connected layers for Q-value estimation
It can be found in the src/dqn.py file.
graph TD;
A[Input: 4x84x84] --> B[Conv2d: 4 → 16, k=8, s=4]
B --> C[ReLU]
C --> D[Conv2d: 16 → 32, k=4, s=2]
D --> E[ReLU]
subgraph "Convolutional Layers"
B
C
D
E
end
E --> F[Flatten: 32x9x9 → 2592]
F --> G[Linear: 2592 → 256]
G --> H[ReLU]
H --> I[Linear: 256 → output_dim]
subgraph "Fully Connected Layers"
G
H
I
end
I --> J[Output: Q-values]
Create a Virtual Environnement and install all dependencies to run the project without any problem :
python3 -m venv .venv
pip install -r requirements.txtTorch device will always be CUDA if it's possible, else it will be on CPU ...
Train a new DQN agent :
python main.py "model_name.pth" --trainEvery agent will be trained on 10M frames, where
If you want to keep the same proportion but train on less frames, here is how you can do :
python main.py "model_name.pth" --train --frames nb_framesLoad a pre-trained model and watch it play:
python main.py "model_name.pth" --loadDuring the inference of our model in the game, we remove the frame skippin to get better results.
You can load the agent you trained the command above, or you can also load pre-trained model. The pre-trained model are based on the architecture you have seen previously.
breakout_1k.pth, model trained on Breakout during 1 000 framesbreakout_100k.pth, model trained on Breakout during 100 000 framesbreakout_1m.pth, model trained on Breakout during 1 000 000 framesbreakout_10m.pth, model trained on Breakout during 10 000 000 framesbreakout_50m.pth, model trained on Breakout during 50 000 000 frames
pong_1m.pth, model trained on Pong during 1 000 000 framespong_10m.pth, model trained on Pong during 10 000 000 frames
Pierre SCHWEITZER (pierre.schweitzer)