-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_cnn.py
82 lines (59 loc) · 2.88 KB
/
model_cnn.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
# CNN Model
import tflearn as tf
def simple_cnn():
input_layer = tf.input_data(shape=[None, 5, 19])
model = tf.conv_1d(input_layer, 256, 4, padding='valid', activation='sigmoid', regularizer='L2')
model = tf.max_pool_1d(model, kernel_size=4)
model = tf.dropout(model, 0.7)
model = tf.fully_connected(model, 11, activation='sigmoid')
sgd = tf.SGD(learning_rate=0.01, lr_decay=0.96, decay_step=32000)
model = tf.regression(model, optimizer=sgd, loss='categorical_crossentropy')
return tf.DNN(model)
def simple_cnn_2d():
input_layer = tf.input_data(shape=[None, 5, 19, 1])
model = tf.conv_2d(input_layer, 256, 3, activation='sigmoid', regularizer='L2')
model = tf.max_pool_2d(model, 2)
'''
model = tf.local_response_normalization(model)
model = tf.conv_2d(model, 512, 3, padding='valid', activation='sigmoid', regularizer='L2')
model = tf.max_pool_2d(model, 2)
model = tf.local_response_normalization(model)
'''
model = tf.dropout(model, 0.7)
model = tf.fully_connected(model, 11, activation='sigmoid')
#model = tf.dropout(model, 0.7)
#sgd = tf.SGD(learning_rate=0.1, lr_decay=0.96, decay_step=1000)
mom = tf.Momentum(0.1, lr_decay=0.1, decay_step=32000, staircase=True)
model = tf.regression(model, optimizer=mom, loss='categorical_crossentropy')
return tf.DNN(model, tensorboard_verbose=0)
def convnet():
model = tf.input_data(shape=[None, 5, 19, 5], name='input')
model = tf.conv_2d(model, 32, 3, activation='relu', regularizer="L2")
model = tf.max_pool_2d(model, 2)
model = tf.local_response_normalization(model)
model = tf.conv_2d(model, 64, 3, activation='relu', regularizer="L2")
model = tf.max_pool_2d(model, 2)
model = tf.local_response_normalization(model)
model = tf.fully_connected(model, 128, activation='tanh')
model = tf.dropout(model, 0.8)
model = tf.fully_connected(model, 256, activation='tanh')
model = tf.dropout(model, 0.8)
model = tf.fully_connected(model, 11, activation='sigmoid')
model = tf.regression(model, optimizer='adam', learning_rate=0.01,
loss='categorical_crossentropy', name='target')
model = tf.DNN(model, tensorboard_verbose=0)
return model
def three_branch_cnn():
input_layer = tf.input_data(shape=[None, 5, 19])
# Branching...
branch1 = tf.conv_1d(input_layer, 256, 5, padding='valid', activation='sigmoid', regularizer='L2')
branch2 = tf.conv_1d(input_layer, 256, 5, padding='valid', activation='sigmoid', regularizer='L2')
branch3 = tf.conv_1d(input_layer, 256, 5, padding='valid', activation='sigmoid', regularizer='L2')
# Merging
model = tf.merge([branch1, branch2, branch3], mode='concat', axis=1)
#model = tf.max_pool_1d(model, kernel_size=5)
model = tf.dropout(model, 0.7)
model = tf.fully_connected(model, 11, activation='sigmoid')
sgd = tf.SGD(learning_rate=0.01, lr_decay=0.96, decay_step=1000)
model = tf.regression(model, optimizer='sgd', loss='categorical_crossentropy')
return tf.DNN(model, tensorboard_verbose=0)