forked from raquelduenass/Air-writing-initial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnets.py
102 lines (82 loc) · 2.96 KB
/
nets.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from keras.models import Model
from keras.layers import Dense, Dropout, Activation, Flatten, Input
from keras.layers import Conv2D, MaxPooling2D
from keras.applications.resnet50 import ResNet50
def gesture_net(img_width, img_height, img_channels, output_dim):
"""
Define model architecture.
# Arguments
img_width: Target image widht.
img_height: Target image height.
img_channels: Target image channels.
output_dim: Dimension of model output.
# Returns
model: A Model instance.
"""
# Input
img_input = Input(shape=(img_height, img_width, img_channels))
x = Conv2D(32, (5, 5), strides=[3,3], padding='valid')(img_input)
x = Activation('relu')(x)
x = Conv2D(32, (3, 3), strides=[2,2], padding='valid')(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=[2,2])(x)
x = Dropout(0.25)(x)
x = Conv2D(64, (3, 3), strides=[1,1], padding='valid')(x)
x = Activation('relu')(x)
x = Conv2D(64, (3, 3), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=[2,2])(x)
x = Dropout(0.25)(x)
x = Conv2D(128, (5, 5), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = Conv2D(128, (3, 3), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=[2,2])(x)
x = Conv2D(256, (3, 3), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = Conv2D(256, (3, 3), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = Conv2D(256, (3, 3), strides=[1,1], padding='same')(x)
x = Activation('relu')(x)
x = MaxPooling2D(pool_size=(2, 2), strides=[2,2])(x)
x = Dropout(0.25)(x)
x = Flatten()(x)
x = Dense(128)(x)
x = Dropout(0.5)(x)
x = Activation('relu')(x)
x = Dense(64)(x)
x = Dropout(0.5)(x)
x = Activation('relu')(x)
x = Dense(output_dim)(x)
x = Activation('softmax')(x)
# Define steering-collision model
model = Model(inputs=[img_input], outputs=[x])
print(model.summary())
return model
def resnet50(img_width, img_height, img_channels, output_dim):
"""
Define model architecture.
# Arguments
img_width: Target image widht.
img_height: Target image height.
img_channels: Target image channels.
output_dim: Dimension of model output.
# Returns
model: A Model instance.
"""
# Input
img_input = Input(shape=(img_height, img_width, img_channels))
# ResNet50
model = ResNet50(include_top=False, weights='imagenet', input_tensor=img_input)
x = model.output
# FC layers
x = Flatten()(x)
x = Dense(1024)(x)
x = Activation('relu')(x)
x = Dropout(0.5)(x)
x = Dense(output_dim)(x)
x = Activation('softmax')(x)
# Define steering-collision model
model = Model(inputs=[img_input], outputs=[x])
print(model.summary())
return model