1
1
"""
2
2
Keras model constructors.
3
3
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)
6
6
7
7
"""
8
8
11
11
from keras .models import Sequential
12
12
from keras .layers import Convolution2D , MaxPooling2D , SimpleRNN , Reshape , BatchNormalization
13
13
from keras .layers import Activation , Dropout , Flatten , Dense
14
+ from keras .regularizers import l2
14
15
15
16
def cnn3_full1 ():
16
17
@@ -81,7 +82,7 @@ def cnn1_full1():
81
82
82
83
img_in = Input (shape = (120 , 160 , 3 ), name = 'img_in' )
83
84
angle_in = Input (shape = (1 ,), name = 'angle_in' )
84
-
85
+
85
86
x = Convolution2D (1 , 3 , 3 )(img_in )
86
87
x = Activation ('relu' )(x )
87
88
x = MaxPooling2D (pool_size = (2 , 2 ))(x )
@@ -131,7 +132,7 @@ def norm_cnn3_full1():
131
132
132
133
133
134
def vision_2D (dropout_frac = .2 ):
134
- '''
135
+ '''
135
136
Network with 4 convolutions, 2 residual shortcuts to predict angle.
136
137
'''
137
138
img_in = Input (shape = (120 , 160 , 3 ), name = 'img_in' )
@@ -144,7 +145,7 @@ def vision_2D(dropout_frac=.2):
144
145
145
146
#Create residual to shortcut
146
147
aux1 = Flatten (name = 'aux1_flat' )(net )
147
- aux1 = Dense (64 , name = 'aux1_dense' )(aux1 )
148
+ aux1 = Dense (64 , name = 'aux1_dense' )(aux1 )
148
149
149
150
net = Convolution2D (128 , 3 , 3 , subsample = (2 ,2 ), border_mode = 'same' , name = 'conv2' )(net )
150
151
net = Dropout (dropout_frac )(net )
@@ -168,4 +169,39 @@ def vision_2D(dropout_frac=.2):
168
169
angle_out = Dense (1 , name = 'angle_out' )(net )
169
170
model = Model (input = [img_in ], output = [angle_out ])
170
171
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