This project implements a Deep Q-Network (DQN) agent for playing Atari games using PyTorch. The implementation includes prioritized experience replay, frame stacking, and various optimizations for better training performance.
- Deep Q-Network implementation with prioritized experience replay
- Convolutional Neural Network architecture optimized for Atari games
- Frame stacking and preprocessing for better state representation
- Configurable hyperparameters for different games
- Weights & Biases integration for experiment tracking
- Comprehensive logging and visualization
- Clone the repository:
git clone https://github.com/youruname/DQN.git
cd DQN- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtTo train the agent on a specific game:
python TRAIN_AGENT.py --config config_name --game game_nameExample:
python TRAIN_AGENT.py --config default --game BreakoutDeterministic-v4To test a trained agent:
python TEST_AGENT.py --config config_name --game game_name --model_path path/to/model.pthExample:
python TEST_AGENT.py --config default --game BreakoutDeterministic-v4 --model_path models/breakout_model.pthThe project uses a configuration system to manage hyperparameters and settings:
config/config.py: Contains general configuration settingsconfig/hyperparameters.py: Contains game-specific hyperparameters
To add a new game configuration:
- Add game-specific hyperparameters in
config/hyperparameters.py - Create a new configuration in
config/config.py
The CNN architecture includes:
- 3 convolutional layers with batch normalization and ReLU activation
- Dropout layers for regularization
- Fully connected layers for Q-value prediction
-
Frame Preprocessing:
- Grayscale conversion
- Resizing to 84x84
- Normalization to [0, 255]
-
Experience Collection:
- Frame stacking (4 frames)
- Prioritized experience replay
- Epsilon-greedy exploration
-
Training:
- Target network for stable learning
- Huber loss for robust training
- Gradient clipping for stability
The agent's performance is tracked using:
- Average reward per episode
- Training loss
- Epsilon value
- Frame processing time
Results are logged to:
- Console output
- Log files
- Weights & Biases (if enabled)
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- DeepMind's original DQN paper
- PyTorch team for the excellent framework
- Gymnasium team for the Atari environments