-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
162 lines (145 loc) · 4.43 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import argparse
import os
from dbres import calculate_dbres_scores
from data_splits import stratified_test_vali_split
from train_resnet import run_model_training
from xgboost_integration import calculate_xgboost_integration_scores
def main(
data_directory,
stratified_directory,
test_size,
vali_size,
cv,
recalc_features,
spectrogram_directory,
model_name,
recalc_output,
dbres_output_directory,
bayesian
):
train_data_directory = os.path.join(stratified_directory, "train_data")
vali_data_directory = os.path.join(stratified_directory, "vali_data")
test_data_directory = os.path.join(stratified_directory, "test_data")
stratified_features = ["Normal", "Abnormal", "Absent", "Present", "Unknown"]
stratified_test_vali_split(
stratified_features,
data_directory,
stratified_directory,
test_size,
vali_size,
cv,
)
run_model_training(
recalc_features,
train_data_directory,
vali_data_directory,
spectrogram_directory,
model_name,
"BinaryPresent",
"data/models",
"binary_present",
bayesian,
None,
)
run_model_training(
recalc_features,
train_data_directory,
vali_data_directory,
spectrogram_directory,
model_name,
"BinaryUnknown",
"data/models",
"binary_unknown",
bayesian,
None,
)
dbres_scores = calculate_dbres_scores(
recalc_output,
test_data_directory,
dbres_output_directory,
"data/models/model_BinaryPresent.pth",
"data/models/model_BinaryUnknown.pth",
)
xgb_scores = calculate_xgboost_integration_scores(
train_data_directory,
test_data_directory,
dbres_output_directory,
"data/models/model_BinaryPresent.pth",
"data/models/model_BinaryUnknown.pth",
bayesian=bayesian
)
return dbres_scores, xgb_scores
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="DBResAndXGBoostIntegration")
parser.add_argument(
"--data_directory",
type=str,
help="The directory containing all of the data.",
default="physionet.org/files/circor-heart-sound/1.0.3/training_data",
)
parser.add_argument(
"--stratified_directory",
type=str,
help="The directory to store the split data.",
default="data/stratified_data",
)
parser.add_argument(
"--vali_size", type=float, default=0.16, help="The size of the test split."
)
parser.add_argument(
"--test_size", type=float, default=0.2, help="The size of the test split."
)
parser.add_argument(
"--cv", type=bool, default=False, help="Whether to run cv."
)
parser.add_argument(
"--recalc_features",
action="store_true",
help="Whether or not to recalculate the log mel spectrograms used as "
"input to the ResNet.",
)
parser.add_argument(
"--no-recalc_features", dest="recalc_features", action="store_false"
)
parser.set_defaults(recalc_features=True)
parser.add_argument(
"--spectrogram_directory",
type=str,
help="The directory in which to save the spectrogram training data.",
default="data/spectrograms",
)
parser.add_argument(
"--model_name",
type=str,
help="The ResNet to train. Current options are resnet50 or resnet50dropout.",
choices=["resnet50", "resnet50dropout"],
default="resnet50dropout",
)
parser.add_argument(
"--recalc_output",
action="store_true",
help="Whether or not to recalculate the output from DBRes.",
)
parser.add_argument(
"--no-recalc_output", dest="recalc_output", action="store_false"
)
parser.set_defaults(recalc_output=True)
parser.add_argument(
"--dbres_output_directory",
type=str,
help="The directory in which DBRes's output is saved.",
default="data/dbres_outputs",
)
parser.add_argument(
'--disable-bayesian',
dest='bayesian',
action='store_false',
default=True,
help='Disable Bayesian features (default: Bayesian is enabled)'
)
args = parser.parse_args()
if "dropout" in args.model_name:
args["bayesian"] = True
else:
args["bayesian"] = False
dbres_scores, xgb_scores = main(**vars(args))