-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
130 lines (112 loc) · 3.9 KB
/
main.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from tensorflow.keras.optimizers import RMSprop, Adam
from tensorflow.keras.layers import ELU, LeakyReLU
from dataset import get_data_invivo
from dataset import get_data_exvivo
from generate_model import generate_model
from finetune import finetune_exvivo
import random
import numpy as np
from train import train
from statistics.roc_all import roc_all
from statistics.prc_all import prc_all
from statistics.cm_all import cm_all
from opts import parse_opts
from test_exvivo import test_exvivo
def main(opt):
random.seed(opt.manual_seed)
np.random.seed(opt.manual_seed)
if opt.data_type == 'invivo':
x_train, y_train, x_val, y_val, x_test, y_test, \
df_val, df_test = get_data_invivo(
proj_dir=opt.proj_dir,
benign_bix=opt.benign_bix,
benign_nobix=opt.benign_nobix,
pca_bix=opt.pca_bix,
exclude_patient=opt.exclude_patient,
x_input=opt.x_input,
invivo_tissue_type=opt.invivo_tissue_type)
model = generate_model(
init=opt.init,
dropout_rate=opt.dropout_rate,
momentum=opt.momentum,
n_input=len(opt.x_input),
n_layer=opt.n_layer)
if opt.train:
if opt.optimizer_function == 'adam':
optimizer = Adam(learning_rate=opt.lr)
train(
model=model,
x_train=x_train,
y_train=y_train,
x_val=x_val,
y_val=y_val,
x_test=x_test,
y_test=y_test,
df_val=df_val,
df_test=df_test,
proj_dir=opt.proj_dir,
batch_size=opt.batch_size,
epoch=opt.train_epoch,
loss=opt.loss_function,
optimizer=optimizer)
if opt.get_stat:
cm_all(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
data_type='invivo')
roc_stat = get_roc(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
bootstrap=opt.bootstrap,
data_type='invivo')
prc_stat = get_prc(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
data_type='invivo')
if opt.data_type == 'exvivo':
x_train, y_train, x_test, y_test, df_test, x_test1, y_test1, \
x_test2, y_test2, df_test1, df_test2 = get_data_exvivo(
proj_dir=opt.proj_dir,
exvivo_data=opt.exvivo_data,
x_input=opt.x_input,
exvivo_tissue_type=opt.exvivo_tissue_type)
# fine tune invivo model
tuned_model = finetune_exvivo(
x_train=x_train,
y_train=y_train,
proj_dir=opt.proj_dir,
saved_model=opt.saved_model,
batch_size=opt.batch_size,
epoch=opt.finetune_epoch,
freeze_layer=opt.freeze_layer)
# model test
test_exvivo(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
wu_split=opt.wu_split,
x_test=x_test,
y_test=y_test,
df_test=df_test,
x_test1=x_test1,
y_test1=y_test1,
x_test2=x_test2,
y_test2=y_test2,
df_test1=df_test1,
df_test2=df_test2)
if opt.get_stat:
cm_all(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
data_type='exvivo')
roc_stat = roc_all(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
bootstrap=opt.bootstrap,
data_type='exvivo')
prc_stat = prc_all(
proj_dir=opt.proj_dir,
output_dir=opt.output_dir,
data_type='exvivo')
if __name__ == '__main__':
opt = parse_opts()
main(opt)