-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmodel.py
More file actions
72 lines (60 loc) · 2.5 KB
/
Copy pathmodel.py
File metadata and controls
72 lines (60 loc) · 2.5 KB
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
64
65
66
67
68
69
70
71
from keras.models import Sequential
from keras.layers.convolutional import Convolution2D
from keras.layers.pooling import MaxPooling2D
from keras.layers.core import Activation, Dropout, Flatten, Dense, Lambda
from keras.layers import ELU
from keras.optimizers import Adam
import numpy as np
import tensorflow as tf
tf.python.control_flow_ops = tf
N_img_height = 66
N_img_width = 220
N_img_channels = 3
def nvidia_model():
inputShape = (N_img_height, N_img_width, N_img_channels)
model = Sequential()
# normalization
model.add(Lambda(lambda x: x/ 127.5 - 1, input_shape = inputShape))
model.add(Convolution2D(24, 5, 5,
subsample=(2,2),
border_mode = 'valid',
init = 'he_normal',
name = 'conv1'))
model.add(ELU())
model.add(Convolution2D(36, 5, 5,
subsample=(2,2),
border_mode = 'valid',
init = 'he_normal',
name = 'conv2'))
model.add(ELU())
model.add(Convolution2D(48, 5, 5,
subsample=(2,2),
border_mode = 'valid',
init = 'he_normal',
name = 'conv3'))
model.add(ELU())
model.add(Dropout(0.5))
model.add(Convolution2D(64, 3, 3,
subsample = (1,1),
border_mode = 'valid',
init = 'he_normal', #gaussian init
name = 'conv4'))
model.add(ELU())
model.add(Convolution2D(64, 3, 3,
subsample= (1,1),
border_mode = 'valid',
init = 'he_normal',
name = 'conv5'))
model.add(Flatten(name = 'flatten'))
model.add(ELU())
model.add(Dense(100, init = 'he_normal', name = 'fc1'))
model.add(ELU())
model.add(Dense(50, init = 'he_normal', name = 'fc2'))
model.add(ELU())
model.add(Dense(10, init = 'he_normal', name = 'fc3'))
model.add(ELU())
# do not put activation at the end because we want to exact output, not a class identifier
model.add(Dense(1, name = 'output', init = 'he_normal'))
adam = Adam(lr=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(optimizer = adam, loss = 'mse')
return model