-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_actor_critic.py
37 lines (31 loc) · 1.05 KB
/
init_actor_critic.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
import torch
import torch.nn as nn
class ActorCritic(nn.Module):
def __init__(self, num_inputs, num_outputs, hidden_size, std=0.0):
super(ActorCritic, self).__init__()
self.critic = nn.Sequential(
nn.Linear(num_inputs, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, 1),
)
self.actor = nn.Sequential(
nn.Linear(num_inputs, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, num_outputs),
nn.Tanh(),
)
self.log_std = nn.Parameter(torch.ones(1, num_outputs) * std)
self.apply(ActorCritic.init_weights)
def forward(self, x):
value = self.critic(x)
mu = self.actor(x)
return mu, value
@staticmethod
def init_weights(m):
if isinstance(m, nn.Linear):
nn.init.normal_(m.weight, mean=0.0, std=0.1)
nn.init.constant_(m.bias, 0.1)