This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
/
model_VGG.py
99 lines (73 loc) · 3.72 KB
/
model_VGG.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
from keras.models import Model
from keras.layers import Input, Conv3D, MaxPooling3D, Dense, GlobalMaxPooling3D, Dropout, BatchNormalization
from keras.optimizers import Adam
from config import *
def get_simplified_VGG_classifier():
inputs = Input((CLASSIFY_INPUT_WIDTH, CLASSIFY_INPUT_HEIGHT, CLASSIFY_INPUT_DEPTH, CLASSIFY_INPUT_CHANNEL))
x = Conv3D(16, (3, 3, 3), padding='same', activation='relu')(inputs)
x = Conv3D(16, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(32, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(32, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(64, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(64, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(64, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
# x = MaxPooling3D(pool_size=(2, 2, 2))(x)
#
# x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
# x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
# x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
x = GlobalMaxPooling3D()(x)
# x = Flatten()(x)
x = Dense(32, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(2, activation='softmax')(x)
model = Model(inputs=inputs, outputs=x)
model.compile(optimizer=Adam(lr=TRAIN_CLASSIFY_LEARNING_RATE), loss='binary_crossentropy', metrics=['accuracy'])
return model
def get_full_VGG_classifier():
inputs = Input((CLASSIFY_INPUT_WIDTH, CLASSIFY_INPUT_HEIGHT, CLASSIFY_INPUT_DEPTH, CLASSIFY_INPUT_CHANNEL))
x = inputs
x = Conv3D(32, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(32, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(64, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(64, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(128, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(256, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(256, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(256, (3, 3, 3), padding='same', activation='relu')(x)
x = MaxPooling3D(pool_size=(2, 2, 2))(x)
if TRAIN_CLASSIFY_USE_BN:
x = BatchNormalization()(x)
x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
x = Conv3D(512, (3, 3, 3), padding='same', activation='relu')(x)
x = GlobalMaxPooling3D()(x)
x = Dense(32, activation='relu')(x)
x = Dropout(0.5)(x)
x = Dense(2, activation='softmax')(x)
model = Model(inputs=inputs, outputs=x)
model.compile(optimizer=Adam(lr=TRAIN_CLASSIFY_LEARNING_RATE), loss='binary_crossentropy', metrics=['accuracy'])
return model