Skip to content

Commit

Permalink
Merge pull request #25 from dangerwheeler/master
Browse files Browse the repository at this point in the history
New model with regularization, hyperparameter tuning
  • Loading branch information
wroscoe authored Jan 26, 2017
2 parents c2671db + d9f48f0 commit ab849a8
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions donkey/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
Keras model constructors.
All models accept 120x160x3 images and output a
single floating point number (ie steering angle)
All models accept 120x160x3 images and output a
single floating point number (ie steering angle)
"""

Expand All @@ -11,6 +11,7 @@
from keras.models import Sequential
from keras.layers import Convolution2D, MaxPooling2D, SimpleRNN, Reshape, BatchNormalization
from keras.layers import Activation, Dropout, Flatten, Dense
from keras.regularizers import l2

def cnn3_full1():

Expand Down Expand Up @@ -81,7 +82,7 @@ def cnn1_full1():

img_in = Input(shape=(120, 160, 3), name='img_in')
angle_in = Input(shape=(1,), name='angle_in')

x = Convolution2D(1, 3, 3)(img_in)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
Expand Down Expand Up @@ -131,7 +132,7 @@ def norm_cnn3_full1():


def vision_2D(dropout_frac=.2):
'''
'''
Network with 4 convolutions, 2 residual shortcuts to predict angle.
'''
img_in = Input(shape=(120, 160, 3), name='img_in')
Expand All @@ -144,7 +145,7 @@ def vision_2D(dropout_frac=.2):

#Create residual to shortcut
aux1 = Flatten(name='aux1_flat')(net)
aux1 = Dense(64, name='aux1_dense')(aux1)
aux1 = Dense(64, name='aux1_dense')(aux1)

net = Convolution2D(128, 3, 3, subsample=(2,2), border_mode='same', name='conv2')(net)
net = Dropout(dropout_frac)(net)
Expand All @@ -168,4 +169,39 @@ def vision_2D(dropout_frac=.2):
angle_out = Dense(1, name='angle_out')(net)
model = Model(input=[img_in], output=[angle_out])
model.compile(optimizer='adam', loss='mean_squared_error')
return model
return model


def regularized_cnn4():
reg = l2(0.005)

img_in = Input(shape=(120, 160,3), name='img_in')
angle_in = Input(shape=(1,), name='angle_in')

x = img_in
x = Convolution2D(4, 3, 3,W_regularizer=reg)(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

x = Convolution2D(8, 3, 3, W_regularizer=reg)(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

x = Convolution2D(16, 3, 3, W_regularizer=reg)(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)

x = Convolution2D(32, 3, 3, W_regularizer=reg)(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2))(x)
x = Flatten()(x)

x = Dense(128, W_regularizer=reg)(x)
x = Activation('linear')(x)
x = Dropout(.2)(x)

angle_out = Dense(1, name='angle_out')(x)

model = Model(input=[img_in], output=[angle_out])
model.compile(optimizer='adam', loss='mean_squared_error')
return model

0 comments on commit ab849a8

Please sign in to comment.