-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
75 lines (60 loc) · 2.17 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
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
import joblib
import numpy as np
import pandas as pd
from preprocessing import pipeline
from typing import List, Tuple
import logging
logger = logging.getLogger("main_log")
def predict_labels(
ecg_leads : List[np.ndarray],
fs : float,
ecg_names : List[str],
model_name : str='international_CO1',
is_binary_classifier : bool=False) -> List[Tuple[str,str]]:
'''
Parameters
----------
model_name : str
Dateiname des Models. In Code-Pfad
ecg_leads : list of numpy-Arrays
EKG-Signale.
fs : float
Sampling-Frequenz der Signale.
ecg_names : list of str
eindeutige Bezeichnung für jedes EKG-Signal.
model_name : str
Name des Models, kann verwendet werden um korrektes Model aus Ordner zu laden
is_binary_classifier : bool
Falls getrennte Modelle für F1 und Multi-Score trainiert werden, wird hier übergeben,
welches benutzt werden soll
Returns
-------
predictions : list of tuples
ecg_name und eure Diagnose
'''
#------------------------------------------------------------------------------
# Euer Code ab hier
predictions = []
data = []
# process data
for idx, ecg_lead in enumerate(ecg_leads):
logger.info(f"Processing {ecg_names[idx]}")
processed_data = pipeline(ecg_signal=ecg_lead, sampling_freq=fs)
data.append(processed_data)
if ((idx+1) % 100)==0:
print(str(idx+1) + "\t Dateien wurden verarbeitet.")
X_test = np.array(data)
# load model
if len(model_name.split(".")) > 1:
model_name = model_name[0]
if is_binary_classifier:
# loads binary model
model = joblib.load("models/" + model_name + '_binary.pkl')
else:
# Loads multilabel model and file to be predicted
model = joblib.load("models/" + model_name + '.pkl')
# predict data
y_test = model.predict(X_test)
predictions = list(zip(ecg_names, y_test))
#------------------------------------------------------------------------------
return predictions # Liste von Tupels im Format (ecg_name,label) - Muss unverändert bleiben!