-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
43 lines (38 loc) · 1.28 KB
/
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
import torch
import torch.nn as nn
from torch.distributions import Normal
class ActorCritic(nn.Module):
def __init__(self, num_inputs, num_outputs, std=0.0):
super(ActorCritic, self).__init__()
hidden_size1 = 256
hidden_size2 = 128
hidden_size3 = 64
self.critic = nn.Sequential(
nn.Linear(num_inputs, hidden_size1),
nn.ReLU(),
nn.Dropout(),
nn.Linear(hidden_size1, hidden_size2),
nn.ReLU(),
nn.Dropout(),
nn.Linear(hidden_size2, hidden_size3),
nn.ReLU(),
nn.Linear(hidden_size3, 1),
)
self.actor = nn.Sequential(
nn.Linear(num_inputs, hidden_size1),
nn.ReLU(),
nn.Dropout(),
nn.Linear(hidden_size1, hidden_size2),
nn.ReLU(),
nn.Dropout(),
nn.Linear(hidden_size2, hidden_size3),
nn.ReLU(),
nn.Linear(hidden_size3, num_outputs),
)
self.log_std = nn.Parameter(torch.ones(1, num_outputs) * std)
def forward(self, x):
value = self.critic(x)
mu = self.actor(x)
std = self.log_std.exp().expand_as(mu)
dist = Normal(mu, std)
return dist, value