Views
No views yet
1git clone https://github.com/KexianShen/parking-env.git
2cd parking-env
3pip install -e .1import gymnasium as gym
2import numpy as np
3import torch
4
5from parking_ppo import Agent
6
7env = gym.make(
8 id="Parking-v0", render_mode="human", observation_type="rgb", action_type="discrete"
9)
10env = gym.wrappers.GrayScaleObservation(env)
11env = gym.wrappers.FrameStack(env, 4)
12
13device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14agent = torch.load("ppo.pth").eval().to(device)
15
16obs, _ = env.reset(seed=42)
17terminated = False
18truncated = False
19
20while not terminated and not truncated:
21 obs = torch.Tensor(np.array(obs)).to(device).unsqueeze(0)
22 with torch.no_grad():
23 action, _, _, _ = agent.get_action_and_value(obs)
24 action = action.cpu().numpy().item()
25 obs, reward, terminated, truncated, info = env.step(action)
26
27env.close()