Views
No views yet
1import torch
2import json
3
4from model import DQN
5from agent import Agent
6from environment import make_env, get_env_dims
7
8#Load the configuration
9with open("config.json", "r") as f:
10 config = json.load(f)
11
12# Create environment. Get action and space dimensions
13env = make_env(config)
14state_size, action_size = get_env_dims(env)
15
16# Instantiate the agent and load the trained policy network
17agent = Agent(state_size, action_size, config)
18agent.policy_net.load_state_dict(torch.load("model.pt"))
19agent.policy_net.eval()
20
21# Enjoy the agent!
22state, _ = env.reset()
23done = False
24while not done:
25 action = agent.act(state, epsilon=0.0) # Act greedily
26 state, reward, terminated, truncated, _ = env.step(action)
27 done = terminated or truncated
28 env.render()