-
Notifications
You must be signed in to change notification settings - Fork 24
/
model.py
63 lines (54 loc) · 2.29 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from keras.models import Sequential
from keras.layers import Convolution2D, ZeroPadding2D, MaxPooling2D
from keras.layers.core import Flatten, Dense, Dropout, Lambda
from keras import backend as K
from keras.optimizers import SGD
from keras.layers import Dense, Dropout, Activation, Flatten
import tensorflow as tf
def global_average_pooling(x):
return tf.reduce_mean(x, (1, 2))
def global_average_pooling_shape(input_shape):
return (input_shape[0], input_shape[3])
def atan_layer(x):
return tf.mul(tf.atan(x), 2)
def atan_layer_shape(input_shape):
return input_shape
def normal_init(shape, name=None):
initial = tf.truncated_normal(shape, stddev=0.1)
return K.variable(initial)
def steering_net():
model = Sequential()
model.add(Convolution2D(24, 5, 5, init = normal_init, subsample= (2, 2), name='conv1_1', input_shape=(66, 200, 3)))
model.add(Activation('relu'))
model.add(Convolution2D(36, 5, 5, init = normal_init, subsample= (2, 2), name='conv2_1'))
model.add(Activation('relu'))
model.add(Convolution2D(48, 5, 5, init = normal_init, subsample= (2, 2), name='conv3_1'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3, init = normal_init, subsample= (1, 1), name='conv4_1'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3, init = normal_init, subsample= (1, 1), name='conv4_2'))
model.add(Activation('relu'))
model.add(Flatten())
model.add(Dense(1164, init = normal_init, name = "dense_0"))
model.add(Activation('relu'))
#model.add(Dropout(p))
model.add(Dense(100, init = normal_init, name = "dense_1"))
model.add(Activation('relu'))
#model.add(Dropout(p))
model.add(Dense(50, init = normal_init, name = "dense_2"))
model.add(Activation('relu'))
#model.add(Dropout(p))
model.add(Dense(10, init = normal_init, name = "dense_3"))
model.add(Activation('relu'))
model.add(Dense(1, init = normal_init, name = "dense_4"))
model.add(Lambda(atan_layer, output_shape = atan_layer_shape, name = "atan_0"))
return model
def get_model():
model = steering_net()
model.compile(loss = 'mse', optimizer = 'Adam')
return model
def load_model(path):
model = steering_net()
model.load_weights(path)
model.compile(loss = 'mse', optimizer = 'Adam')
return model