RL Agents Playing Parking-v0
Here are trained models of RL agents playing Parking-v0.
Get Started
- Install the parking-env package.
git clone https://github.com/KexianShen/parking-env.git
cd parking-env
pip install -e .
- Run the provided example.ipynb notebook or execute the following code:
import gymnasium as gym
import numpy as np
import torch
from parking_ppo import Agent
env = gym.make(
id="Parking-v0", render_mode="human", observation_type="rgb", action_type="discrete"
)
env = gym.wrappers.GrayScaleObservation(env)
env = gym.wrappers.FrameStack(env, 4)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
agent = torch.load("ppo.pth").eval().to(device)
obs, _ = env.reset(seed=42)
terminated = False
truncated = False
while not terminated and not truncated:
obs = torch.Tensor(np.array(obs)).to(device).unsqueeze(0)
with torch.no_grad():
action, _, _, _ = agent.get_action_and_value(obs)
action = action.cpu().numpy().item()
obs, reward, terminated, truncated, info = env.step(action)
env.close()