-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtrain.py
70 lines (58 loc) · 2.43 KB
/
train.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
from keras import Model
from keras.layers import Input, Conv1D, ReLU, BatchNormalization, Add, AveragePooling1D, Dense, Flatten, Dropout
def get_residual_block_type_one(input_tensor, c, k):
multiplied_size = int(c * k)
x = Conv1D(multiplied_size, 9, strides=1,
use_bias=False, padding='same')(input_tensor)
x = BatchNormalization()(x)
x = ReLU()(x)
x = Conv1D(multiplied_size, 9, strides=1,
use_bias=False, padding='same')(x)
x = BatchNormalization()(x)
x = Add()([x, input_tensor])
x = ReLU()(x)
return x
def get_residual_block_type_two(input_tensor, c, k):
multiplied_size = int(c * k)
x1 = Conv1D(multiplied_size, 9, strides=2,
use_bias=False, padding='same')(input_tensor)
x1 = BatchNormalization()(x1)
x1 = ReLU()(x1)
x1 = Conv1D(multiplied_size, 9, strides=1,
use_bias=False, padding='same')(x1)
x1 = BatchNormalization()(x1)
x2 = Conv1D(multiplied_size, 1, strides=2,
use_bias=False, padding='same')(input_tensor)
x2 = BatchNormalization()(x2)
x2 = ReLU()(x2)
x = Add()([x1, x2])
x = ReLU()(x)
return x
DROPOUT_RATE = 0.5
def get_tc_resnet_8(input_shape, num_classes, k):
input_layer = Input(input_shape)
x = Conv1D(int(16 * k), 3, strides=1, use_bias=False,
padding='same')(input_layer)
x = get_residual_block_type_two(x, 24, k)
x = get_residual_block_type_two(x, 32, k)
x = get_residual_block_type_two(x, 48, k)
x = AveragePooling1D(3, 1)(x)
x = Flatten()(x)
x = Dropout(DROPOUT_RATE)(x)
output_layer = Dense(num_classes, activation='softmax')(x)
return Model(inputs=input_layer, outputs=output_layer)
def get_tc_resnet_14(input_shape, num_classes, k):
input_layer = Input(input_shape)
x = Conv1D(int(16 * k), 3, strides=1, use_bias=False,
padding='same')(input_layer)
x = get_residual_block_type_two(x, 24, k)
x = get_residual_block_type_one(x, 24, k)
x = get_residual_block_type_two(x, 32, k)
x = get_residual_block_type_one(x, 32, k)
x = get_residual_block_type_two(x, 48, k)
x = get_residual_block_type_one(x, 48, k)
x = AveragePooling1D(3, 1)(x)
x = Flatten()(x)
x = Dropout(DROPOUT_RATE)(x)
output_layer = Dense(num_classes, activation='softmax')(x)
return Model(inputs=input_layer, outputs=output_layer)