-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
43 lines (36 loc) · 1.65 KB
/
predict.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
import numpy as np
import warnings
import argparse
warnings.filterwarnings("ignore")
from tensorflow.keras.models import load_model
from tensorflow.keras.optimizers import Adam
from datasets import ECGSequence
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get performance on test set from hdf5')
parser.add_argument('path_to_hdf5', type=str,
help='path to hdf5 file containing tracings')
parser.add_argument('path_to_model', # or model_date_order.hdf5
help='file containing training model.')
parser.add_argument('--dataset_name', type=str, default='tracings',
help='name of the hdf5 dataset containing tracings')
parser.add_argument('--output_file', default="./dnn_output.npy", # or predictions_date_order.csv
help='output npy file.')
parser.add_argument('-bs', type=int, default=32,
help='Batch size.')
args, unk = parser.parse_known_args()
if unk:
warnings.warn("Unknown arguments:" + str(unk) + ".")
print()
print("Data Path:", args.path_to_hdf5)
print("Model Path:", args.path_to_model)
print("Dataset Name:", args.dataset_name)
print("Output Path:", args.output_file)
# Import data
seq = ECGSequence(args.path_to_hdf5, args.dataset_name, batch_size=args.bs)
# Import model
model = load_model(args.path_to_model, compile=False)
model.compile(loss='binary_crossentropy', optimizer=Adam())
y_score = model.predict(seq, verbose=1)
# Generate dataframe
np.save(args.output_file, y_score)
print("Output predictions saved")