|
|
--- |
|
|
tags: |
|
|
- ALE/SpaceInvaders-v5 |
|
|
- reinforcement-learning |
|
|
- dqn |
|
|
- atari |
|
|
- gymnasium |
|
|
- pytorch |
|
|
model-index: |
|
|
- name: DQN-ALE-SpaceInvaders |
|
|
results: |
|
|
- task: |
|
|
type: reinforcement-learning |
|
|
name: reinforcement-learning |
|
|
dataset: |
|
|
name: ALE/SpaceInvaders-v5 |
|
|
type: ALE/SpaceInvaders-v5 |
|
|
metrics: |
|
|
- type: mean_reward |
|
|
value: 730.50 +/- 240.93 |
|
|
name: mean_reward |
|
|
verified: false |
|
|
--- |
|
|
|
|
|
# Deep Q-Network (DQN) Agent playing ALE/SpaceInvaders-v5 |
|
|
|
|
|
This is a trained Deep Q-Network (DQN) agent for the Atari game ALE/SpaceInvaders-v5. |
|
|
|
|
|
The model was trained using the code available [here](https://github.com/giansimone/dqn-ale-spaceinvaders/). |
|
|
|
|
|
## Usage |
|
|
To load and use this model for inference: |
|
|
|
|
|
```python |
|
|
import torch |
|
|
import json |
|
|
|
|
|
from model import DQN |
|
|
from agent import Agent |
|
|
from environment import make_env, get_env_dims |
|
|
|
|
|
#Load the configuration |
|
|
with open("config.json", "r") as f: |
|
|
config = json.load(f) |
|
|
|
|
|
# Create environment. Get action and space dimensions |
|
|
env = make_env(config) |
|
|
state_size, action_size = get_env_dims(env) |
|
|
|
|
|
# Instantiate the agent and load the trained policy network |
|
|
agent = Agent(state_size, action_size, config) |
|
|
agent.policy_net.load_state_dict(torch.load("model.pt")) |
|
|
agent.policy_net.eval() |
|
|
|
|
|
# Enjoy the agent! |
|
|
state, _ = env.reset() |
|
|
done = False |
|
|
while not done: |
|
|
action = agent.act(state, epsilon=0.0) # Act greedily |
|
|
state, reward, terminated, truncated, _ = env.step(action) |
|
|
done = terminated or truncated |
|
|
env.render() |
|
|
``` |
|
|
|