-
Notifications
You must be signed in to change notification settings - Fork 817
/
mujoco_model.py
57 lines (49 loc) · 1.93 KB
/
mujoco_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
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
import parl
class MujocoModel(parl.Model):
def __init__(self, obs_dim, act_dim):
super(MujocoModel, self).__init__()
hid1_size = 256
hid2_size = 256
value1 = np.sqrt(1.0 / obs_dim)
value2 = np.sqrt(1.0 / hid1_size)
value3 = np.sqrt(1.0 / hid2_size)
param_attr1 = paddle.framework.ParamAttr(
initializer=paddle.nn.initializer.Uniform(
low=-value1, high=value1))
param_attr2 = paddle.framework.ParamAttr(
initializer=paddle.nn.initializer.Uniform(
low=-value2, high=value2))
param_attr3 = paddle.framework.ParamAttr(
initializer=paddle.nn.initializer.Uniform(
low=-value3, high=value3))
self.fc1 = nn.Linear(
obs_dim, hid1_size, weight_attr=param_attr1, bias_attr=param_attr1)
self.fc2 = nn.Linear(
hid1_size,
hid2_size,
weight_attr=param_attr2,
bias_attr=param_attr2)
self.fc3 = nn.Linear(
hid2_size, act_dim, weight_attr=param_attr3, bias_attr=param_attr3)
def forward(self, obs):
hid1 = F.tanh(self.fc1(obs))
hid2 = F.tanh(self.fc2(hid1))
means = self.fc3(hid2)
return means