-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnature.py
27 lines (22 loc) · 926 Bytes
/
nature.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
import keras
from keras import layers
zero = keras.initializers.Zeros()
base_weights = 'files/ac-base.weights.h5'
def build_model_ac(input_shape, num_actions, init_zero = False, load_weights = True):
inputs = layers.Input(shape=input_shape)
x = layers.Conv2D(32, 8, strides=4, activation="relu")(inputs)
x = layers.Conv2D(64, 4, strides=2, activation="relu")(x)
x = layers.Conv2D(64, 3, strides=1, activation="relu")(x)
x = layers.Flatten()(x)
x = layers.Dense(512, activation="relu")(x)
if init_zero:
actor = layers.Dense(num_actions,kernel_initializer=zero, activation="softmax")(x)
critic = layers.Dense(1, kernel_initializer=zero)(x)
else:
actor = layers.Dense(num_actions, activation="softmax")(x)
critic = layers.Dense(1)(x)
model = keras.Model(inputs=inputs, outputs=[actor, critic])
print(model.summary())
if load_weights:
model.load_weights(base_weights)
return model