Downloads · 30 days
6
35% of all-time downloads
sam522/ppo-lunarlanding-v2
ppo-lunarlanding-v2 is a reinforcement learning model from sam522. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product.
This is a trained model of a PPO agent playing LunarLander-v2 using a custom implementation.
Downloads · 30 days
6
35% of all-time downloads
All-time downloads
17
Public
Repo size
65.1 KB
Likes
0
Public
Click a slice to open those files.
.pt65.1 KB · 75%
From the Hugging Face model README
This is a trained model of a PPO agent playing LunarLander-v2 using a custom implementation.
import torch
import gymnasium as gym
import torch.nn as nn
import torch.nn.functional as F
from torch.distributions import Categorical
import numpy as np
# Define the Actor network
class Actor(nn.Module):
def __init__(self, state_dim, action_dim, hidden_size=64):
super().__init__()
self.network = nn.Sequential(
nn.Linear(state_dim, hidden_size),
nn.Tanh(),
nn.Linear(hidden_size, hidden_size),
nn.Tanh(),
nn.Linear(hidden_size, action_dim)
)
def forward(self, x):
return self.network(x)
# Load the model
checkpoint = torch.load("model.pt", map_location='cpu')
actor = Actor(state_dim=8, action_dim=4, hidden_size=checkpoint['config']['hidden_size'])
actor.load_state_dict(checkpoint['actor_state_dict'])
actor.eval()
# Test the agent
env = gym.make("LunarLander-v2")
state, _ = env.reset()
total_reward = 0
for _ in range(1000): # Max steps
with torch.no_grad():
state_tensor = torch.FloatTensor(state).unsqueeze(0)
logits = actor(state_tensor)
action = torch.argmax(logits, dim=-1).item()
state, reward, terminated, truncated, _ = env.step(action)
total_reward += reward
if terminated or truncated:
break
print(f"Total reward: {total_reward:.2f}")
This model was trained as part of the Hugging Face Deep RL Course.