-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv3DNet.py
65 lines (52 loc) · 2.14 KB
/
conv3DNet.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
from keras.layers import *
from keras.models import Sequential
from keras.regularizers import l2
def Conv(filters=16, kernel_size=(3,3,3), activation='relu', input_shape=None):
if input_shape:
return Conv3D(filters=filters, kernel_size=kernel_size, padding='Same',
activation=None, input_shape=input_shape,
kernel_initializer="he_normal")
# kernel_initializer="he_normal", kernel_regularizer=l2(1e-4))
else:
return Conv3D(filters=filters, kernel_size=kernel_size, padding='Same',
activation=None,
kernel_initializer="he_normal")
# kernel_initializer="he_normal", kernel_regularizer=l2(1e-4))
def BatchNormalization_Relu(activation='relu'):
return [BatchNormalization(), Activation(activation=activation)]
def BatchNormalization_Relu_MaxPooling3D(activation='relu'):
return [BatchNormalization(), Activation(activation=activation), MaxPool3D()]
# Define Model
def CNN3D(input_dim, num_classes):
model = Sequential([
Conv(8, (3,3,3), input_shape=input_dim),
*BatchNormalization_Relu(),
Conv(16, (3,3,3)),
*BatchNormalization_Relu_MaxPooling3D(),
Conv(16, (3,3,3)),
*BatchNormalization_Relu(),
Conv(32, (3,3,3)),
*BatchNormalization_Relu_MaxPooling3D(),
Conv(32, (3,3,3)),
*BatchNormalization_Relu(),
Conv(64, (3,3,3)),
*BatchNormalization_Relu_MaxPooling3D(),
Conv(64, (3,3,3)),
*BatchNormalization_Relu(),
Conv(128, (3,3,3)),
*BatchNormalization_Relu_MaxPooling3D(),
Conv(128, (3,3,3)),
*BatchNormalization_Relu(),
Conv(256, (3,3,3)),
*BatchNormalization_Relu(),
Conv(512, (3,3,3)), # -11
*BatchNormalization_Relu_MaxPooling3D(),
Flatten(),
Dense(1024, activation='relu'),
Dropout(0.5),
Dense(1024, activation='relu'),
Dropout(0.5),
Dense(num_classes),
Activation(activation='softmax'),
])
return model