-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
44 lines (35 loc) · 987 Bytes
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from torch import nn
"""
fc1_units = 64
fc2_units = 64
"""
# Policy and value model
class ActorCriticNetwork(nn.Module):
def __init__(self, obs_space_size, action_space_size):
super().__init__()
self.shared_layers = nn.Sequential(
nn.Linear(obs_space_size, 64),
nn.ReLU(),
nn.Linear(64, 64),
nn.ReLU())
self.policy_layers = nn.Sequential(
nn.Linear(64, 64),
nn.ReLU(),
nn.Linear(64, action_space_size))
self.value_layers = nn.Sequential(
nn.Linear(64, 64),
nn.ReLU(),
nn.Linear(64, 1))
def value(self, obs):
z = self.shared_layers(obs)
value = self.value_layers(z)
return value
def policy(self, obs):
z = self.shared_layers(obs)
policy_logits = self.policy_layers(z)
return policy_logits
def forward(self, obs):
z = self.shared_layers(obs)
policy_logits = self.policy_layers(z)
value = self.value_layers(z)
return policy_logits, value