MCPcopy Index your code
hub / github.com/rlcode/reinforcement-learning / ActorCritic

Class ActorCritic

3-atari/2-ppo.py:41–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39
40# Nature CNN shared trunk + policy and value heads.
41class ActorCritic(nn.Module):
42 def __init__(self, n_actions):
43 super().__init__()
44 self.conv = nn.Sequential(
45 _ortho(nn.Conv2d(4, 32, kernel_size=8, stride=4), 2 ** 0.5), nn.ReLU(),
46 _ortho(nn.Conv2d(32, 64, kernel_size=4, stride=2), 2 ** 0.5), nn.ReLU(),
47 _ortho(nn.Conv2d(64, 64, kernel_size=3, stride=1), 2 ** 0.5), nn.ReLU(),
48 nn.Flatten(),
49 _ortho(nn.Linear(64 * 7 * 7, 512), 2 ** 0.5), nn.ReLU(),
50 )
51 # gain=0.01 keeps the initial action distribution close to uniform.
52 self.policy = _ortho(nn.Linear(512, n_actions), 0.01)
53 self.value = _ortho(nn.Linear(512, 1), 1.0)
54
55 def forward(self, x):
56 h = self.conv(x.float() / 255.0)
57 return self.policy(h), self.value(h).squeeze(-1)
58
59
60def compute_gae(rewards, values, dones, last_value):

Callers 1

2-ppo.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected