File size: 1,510 Bytes
5b07a48 0fab0aa 5b07a48 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ---
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()
```
|