-
Notifications
You must be signed in to change notification settings - Fork 3
/
model.py
43 lines (34 loc) · 1.41 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
from keras.layers import Conv2D, Dense, Input, Flatten, Dropout, BatchNormalization
from keras.models import Model
def build_model(state_size, n_actions,
conv_filters=(32, 32, 32, 32),
conv_sizes=(3, 3, 3, 3),
conv_strides=(2, 2, 2, 2),
pads=['same']*4,
conv_droputs=[0.0]*4,
fc_sizes=(512, 256),
fc_dropouts=[0.]*2,
batch_norm=True,
activation='relu'):
inputs = Input(shape=state_size)
conv = inputs
for (f_num, f_size, f_stride, pad, droput) in zip(conv_filters, conv_sizes, conv_strides, pads, conv_droputs):
conv = Conv2D(f_num, f_size, f_size,
border_mode=pad,
subsample=(f_stride, f_stride),
activation=activation,
dim_ordering='th')(conv)
if batch_norm:
conv = BatchNormalization(mode=0, axis=1)(conv)
if droput > 0:
conv = Dropout(droput)(conv)
fc = Flatten()(conv)
for fc_size, dropout in zip(fc_sizes, fc_dropouts):
fc = Dense(fc_size, activation=activation)(fc)
if batch_norm:
fc = BatchNormalization(mode=1)(fc)
if droput > 0:
fc = Dropout(droput)(fc)
actor = Dense(n_actions, activation='softmax')(fc)
model = Model(input=inputs, output=actor)
return model