Skip to content

Commit ab849a8

Browse files
authored
Merge pull request #25 from dangerwheeler/master
New model with regularization, hyperparameter tuning
2 parents c2671db + d9f48f0 commit ab849a8

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

donkey/models.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
Keras model constructors.
33
4-
All models accept 120x160x3 images and output a
5-
single floating point number (ie steering angle)
4+
All models accept 120x160x3 images and output a
5+
single floating point number (ie steering angle)
66
77
"""
88

@@ -11,6 +11,7 @@
1111
from keras.models import Sequential
1212
from keras.layers import Convolution2D, MaxPooling2D, SimpleRNN, Reshape, BatchNormalization
1313
from keras.layers import Activation, Dropout, Flatten, Dense
14+
from keras.regularizers import l2
1415

1516
def cnn3_full1():
1617

@@ -81,7 +82,7 @@ def cnn1_full1():
8182

8283
img_in = Input(shape=(120, 160, 3), name='img_in')
8384
angle_in = Input(shape=(1,), name='angle_in')
84-
85+
8586
x = Convolution2D(1, 3, 3)(img_in)
8687
x = Activation('relu')(x)
8788
x = MaxPooling2D(pool_size=(2, 2))(x)
@@ -131,7 +132,7 @@ def norm_cnn3_full1():
131132

132133

133134
def vision_2D(dropout_frac=.2):
134-
'''
135+
'''
135136
Network with 4 convolutions, 2 residual shortcuts to predict angle.
136137
'''
137138
img_in = Input(shape=(120, 160, 3), name='img_in')
@@ -144,7 +145,7 @@ def vision_2D(dropout_frac=.2):
144145

145146
#Create residual to shortcut
146147
aux1 = Flatten(name='aux1_flat')(net)
147-
aux1 = Dense(64, name='aux1_dense')(aux1)
148+
aux1 = Dense(64, name='aux1_dense')(aux1)
148149

149150
net = Convolution2D(128, 3, 3, subsample=(2,2), border_mode='same', name='conv2')(net)
150151
net = Dropout(dropout_frac)(net)
@@ -168,4 +169,39 @@ def vision_2D(dropout_frac=.2):
168169
angle_out = Dense(1, name='angle_out')(net)
169170
model = Model(input=[img_in], output=[angle_out])
170171
model.compile(optimizer='adam', loss='mean_squared_error')
171-
return model
172+
return model
173+
174+
175+
def regularized_cnn4():
176+
reg = l2(0.005)
177+
178+
img_in = Input(shape=(120, 160,3), name='img_in')
179+
angle_in = Input(shape=(1,), name='angle_in')
180+
181+
x = img_in
182+
x = Convolution2D(4, 3, 3,W_regularizer=reg)(x)
183+
x = Activation('relu')(x)
184+
x = MaxPooling2D(pool_size=(2, 2))(x)
185+
186+
x = Convolution2D(8, 3, 3, W_regularizer=reg)(x)
187+
x = Activation('relu')(x)
188+
x = MaxPooling2D(pool_size=(2, 2))(x)
189+
190+
x = Convolution2D(16, 3, 3, W_regularizer=reg)(x)
191+
x = Activation('relu')(x)
192+
x = MaxPooling2D(pool_size=(2, 2))(x)
193+
194+
x = Convolution2D(32, 3, 3, W_regularizer=reg)(x)
195+
x = Activation('relu')(x)
196+
x = MaxPooling2D(pool_size=(2, 2))(x)
197+
x = Flatten()(x)
198+
199+
x = Dense(128, W_regularizer=reg)(x)
200+
x = Activation('linear')(x)
201+
x = Dropout(.2)(x)
202+
203+
angle_out = Dense(1, name='angle_out')(x)
204+
205+
model = Model(input=[img_in], output=[angle_out])
206+
model.compile(optimizer='adam', loss='mean_squared_error')
207+
return model

0 commit comments

Comments
 (0)