Downloads · 30 days
0
Nharen/Reward_Rush_DQN_Lunar_Lander
Reward_Rush_DQN_Lunar_Lander is a reinforcement learning model from Nharen. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
This repository contains a Deep Q-Network agent trained for the LunarLander-v3 environment.
Downloads · 30 days
0
Access
Public
Updated Dec 31, 2025
Repo size
206 KB
Likes
0
Public
Click a slice to open those files.
.mp4173 KB · 82%
From the Hugging Face model README
This repository contains a Deep Q-Network agent trained for the LunarLander-v3 environment.
The model uses a simple multi-layer perceptron structure with the following specifications:
import torch
import torch.nn as nn
import gymnasium as gym
import numpy as np
from huggingface_hub import hf_hub_download
class LunarNet(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(8, 32)
self.fc2 = nn.Linear(32, 32)
self.fc3 = nn.Linear(32, 4)
def forward(self, x):
x = torch.relu(self.fc1(x))
x = torch.relu(self.fc2(x))
return self.fc3(x)
def run_evaluation():
repo_id = "Nharen/Reward_Rush_DQN_Lunar_Lander"
filename = "lunar_lander_dqn.pth"
path = hf_hub_download(repo_id=repo_id, filename=filename)
model = LunarNet()
checkpoint = torch.load(path, map_location='cpu', weights_only=True)
if isinstance(checkpoint, dict) and "policy_net_state_dict" in checkpoint:
state_dict = checkpoint["policy_net_state_dict"]
else:
state_dict = checkpoint
model.load_state_dict(state_dict)
model.eval()
env = gym.make("LunarLander-v3")
total_rewards = []
for _ in range(100):
state, _ = env.reset()
episode_reward = 0
done = False
while not done:
state_t = torch.as_tensor(state, dtype=torch.float32).unsqueeze(0)
with torch.no_grad():
action = model(state_t).argmax(dim=1).item()
state, reward, terminated, truncated, _ = env.step(action)
episode_reward += reward
done = terminated or truncated
total_rewards.append(episode_reward)
print(f"Average Reward: {np.mean(total_rewards)}")
env.close()
if __name__ == "__main__":
run_evaluation()