Views
No views yet
LunarLander-v3 environment from Gymnasium.1import torch
2import gymnasium as gym
3from model import QNetwork
4
5# Initialize environment and load weights
6env = gym.make("LunarLander-v3", render_mode="human")
7model = QNetwork(state_size=8, action_size=4)
8model.load_state_dict(torch.load("model.pt", map_location="cpu"))
9model.eval()
10
11state, _ = env.reset()
12done = False
13
14while not done:
15 state_tensor = torch.from_numpy(state).float().unsqueeze(0)
16 with torch.no_grad():
17 action = torch.argmax(model(state_tensor)).item()
18 state, reward, terminated, truncated, _ = env.step(action)
19 done = terminated or truncated
20
21env.close()