Downloads · 30 days
0
Tejas-Anvekar/Reinforce-Pixelcopter-PLE-v0
Reinforce-Pixelcopter-PLE-v0 is a reinforcement learning model from Tejas-Anvekar. 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 Reinforce agent playing Pixelcopter-PLE-v0. The agent was trained using a custom implementation of the Policy Gradient (Reinforce) algorithm using PyTorch.
Downloads · 30 days
0
Access
Public
Updated Jan 6, 2026
Repo size
80.2 KB
Likes
0
Public
Click a slice to open those files.
.pt40.1 KB · 51%
From the Hugging Face model README
This is a trained Reinforce agent playing Pixelcopter-PLE-v0. The agent was trained using a custom implementation of the Policy Gradient (Reinforce) algorithm using PyTorch.
Pixelcopter-PLE-v0 (Gym Pygame Learning Environment)| Metric | Value |
|---|---|
| Mean Reward | 44.60 +/- 32.36 |
| Evaluation Episodes | 10 |
The agent was trained using the following hyperparameters:
The policy uses a deeper network for this environment compared to CartPole:
To use this model, you need gym, gym_pygame, and torch installed.
⚠️ Note: When loading the model with torch.load, you might get a warning about "suspicious pickle files" or "weights_only=False". This is standard for PyTorch models that save the full model structure. Please ignore the warning and trust the source if you are running this locally.
import gym
import gym_pygame
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from huggingface_hub import hf_hub_download
# 1. Define the Policy class (MUST be present and match the training architecture)
class Policy(nn.Module):
def __init__(self, s_size, a_size, h_size):
super(Policy, self).__init__()
self.fc1 = nn.Linear(s_size, h_size)
self.fc2 = nn.Linear(h_size, h_size*2) # Note the extra layer size
self.fc3 = nn.Linear(h_size*2, a_size)
def forward(self, x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return F.softmax(x, dim=1)
def act(self, state):
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
state = torch.from_numpy(state).float().unsqueeze(0).to(device)
probs = self.forward(state).cpu()
m = torch.distributions.Categorical(probs)
action = m.sample()
return action.item(), m.log_prob(action)
# 2. Download the model
repo_id = "Tejas-Anvekar/Reinforce-Pixelcopter-PLE-v0" # Replace with your Repo ID
filename = "model.pt"
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
# 3. Load the model
# We set weights_only=False because we are loading the full model structure
model = torch.load(model_path, map_location=torch.device('cpu'))
model.eval()
# 4. Evaluate
env = gym.make("Pixelcopter-PLE-v0")
state = env.reset()
done = False
total_reward = 0
print("Agent playing...")
while not done:
action, _ = model.act(state)
state, reward, done, _ = env.step(action)
total_reward += reward
env.render()
print(f"Game Over! Total Reward: {total_reward}")
env.close()