A streamlined setup for training and evaluating reinforcement learning agents on Atari 2600 games.
Project description
Atari Reinforcement Learning with Stable-Baselines3 & RL Zoo
This project provides a streamlined setup for training and evaluating reinforcement learning agents on Atari 2600 games. It is based on the workflow demonstrated in this YouTube tutorial and uses a collection of simple shell scripts to manage common tasks like training, evaluation, and video recording.
The core of the project leverages powerful libraries like Stable-Baselines3 and RL-Baselines3-Zoo to do the heavy lifting.
https://github.com/user-attachments/assets/68943893-f0ef-4e58-8dbb-88a6ae038560
✨ Key Features
- Cross-Platform Workflow: Simple Python scripts (
train.py,enjoy.pyandrecord-video.py) to abstract away complex commands and ensure compatibility across platforms. - Powered by RL Zoo: Leverages the robust framework of
rl-zoo3for training, evaluation, and hyperparameter management. - Easy to Customize: Scripts can be easily modified to train on different Atari games or with different RL algorithms.
🚀 Installation
The recommended way to install this tool is directly from PyPI:
pip install atari-reinforcement-learning
This will make the atari-rl command available in your environment.
[!CAUTION] Atari ROMs: This project uses
ale-pyto automatically download and install the necessary Atari ROMs during the dependency installation process. By proceeding with the installation, you are confirming that you have the legal right to use these ROMs.
🎮 Usage
Train a New Agent
To start training an agent from scratch, run the training script. This will save logs and the trained model in the logs/ directory.
atari-rl train
Resume Training
If a training session was interrupted, you can resume from the last saved checkpoint.
atari-rl train --resume
Watch the Agent Play
Once you have a trained model, you can watch it play the game. This script will load the best-performing model from your training history.
atari-rl enjoy
[!TIP] To watch a specific experiment, add
--exp-id n, wherenis the experiment number.
Record a Video
To save a video of your agent playing, use the recording script. The video will be saved in a videos/ folder inside the corresponding log directory.
atari-rl record-video
[!TIP] You can also specify the experiment ID with
--exp-id nand the output format with--format <svg|mp4|all>.
🛠️ Developer Setup
If you want to contribute to the project or modify the code, follow these steps to set up a development environment.
-
Clone the repository
git clone https://github.com/CosmicDNA/atari-reinforcement-learning.git cd atari-reinforcement-learning
-
Create and activate a virtual environment
python -m venv .venv source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
-
Install in editable mode with development dependencies This installs the package in a way that your code changes are immediately reflected, and includes tools like
ruffandpytestfor development.- Using
uv(recommended for speed):pip install uv uv pip install -e ".[dev]"
- Using
pip:pip install -e ".[dev]"
- Using
🔧 Customization & Configuration
This tool uses a .env file in your current working directory to manage experiment configurations. This allows you to maintain separate configurations for different experiments in different folders.
How it Works
When you run any atari-rl command for the first time in a new directory, the tool will automatically create a .env file for you with default settings.
To customize an experiment, simply edit the values in this .env file. For example, to train a DQN agent on Pong, you would modify your .env file like this:
ALGO="dqn"
ENV="ALE/Pong-v5"
🤝🏿 Acknowledgements
This project stands on the shoulders of the following giants:
- RL Baselines3 Zoo: A Training Framework for Stable Baselines3 Reinforcement Learning Agents.
- Gymnasium: A Python library for developing and comparing reinforcement learning algorithms.
- PyTorch: An open-source machine learning framework that accelerates the path from research prototyping to production deployment.
- The Arcade Learning Environment: A simple framework that allows researchers and hobbyists to develop AI agents for Atari 2600 games.
- OpenCV: Pre-built CPU-only OpenCV packages for Python.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file atari_reinforcement_learning-1.0.7.tar.gz.
File metadata
- Download URL: atari_reinforcement_learning-1.0.7.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae1e113bee8b1450e883b7a923f3e7cb6751273e792c308842ae63ce1fe4056b
|
|
| MD5 |
4d13787e0d802d1cef3b17df75e68ee8
|
|
| BLAKE2b-256 |
1e96c76a25ed4efd43b417d026fdb3b51560869d2e687fe3faaf919d11e2fe7f
|
Provenance
The following attestation bundles were made for atari_reinforcement_learning-1.0.7.tar.gz:
Publisher:
pypi-publish.yml on CosmicDNA/atari-reinforcement-learning
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
atari_reinforcement_learning-1.0.7.tar.gz -
Subject digest:
ae1e113bee8b1450e883b7a923f3e7cb6751273e792c308842ae63ce1fe4056b - Sigstore transparency entry: 289548568
- Sigstore integration time:
-
Permalink:
CosmicDNA/atari-reinforcement-learning@6047b89adacbe6cbdcddcafb195c22f02e9a009e -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/CosmicDNA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@6047b89adacbe6cbdcddcafb195c22f02e9a009e -
Trigger Event:
push
-
Statement type:
File details
Details for the file atari_reinforcement_learning-1.0.7-py3-none-any.whl.
File metadata
- Download URL: atari_reinforcement_learning-1.0.7-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d083f1cde63a5ef573bc207360256f05da978045171b06201b0285422566ad44
|
|
| MD5 |
5f08bf188f843a8fce8eda4b62427850
|
|
| BLAKE2b-256 |
4dd1f3a84dd706dcc6c50d99e6268aa1d2eaa28c63c78950dcddce8d498c3ee3
|
Provenance
The following attestation bundles were made for atari_reinforcement_learning-1.0.7-py3-none-any.whl:
Publisher:
pypi-publish.yml on CosmicDNA/atari-reinforcement-learning
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
atari_reinforcement_learning-1.0.7-py3-none-any.whl -
Subject digest:
d083f1cde63a5ef573bc207360256f05da978045171b06201b0285422566ad44 - Sigstore transparency entry: 289548672
- Sigstore integration time:
-
Permalink:
CosmicDNA/atari-reinforcement-learning@6047b89adacbe6cbdcddcafb195c22f02e9a009e -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/CosmicDNA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@6047b89adacbe6cbdcddcafb195c22f02e9a009e -
Trigger Event:
push
-
Statement type: