Spaces:
Sleeping
Sleeping
Delete prediction.py
Browse files- prediction.py +0 -27
prediction.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import pandas as pd
|
| 3 |
-
from preprocessing import preprocess_eeg_file
|
| 4 |
-
from preprocessing_2dcnn import convert_epoch_to_spectrogram
|
| 5 |
-
|
| 6 |
-
def aggregate_predictions(spectrogram_list, model, threshold=0.5):
|
| 7 |
-
X = np.array([np.transpose(s, (1, 2, 0)) for s in spectrogram_list]) # (n, H, W, C)
|
| 8 |
-
preds = model.predict(X, verbose=0)
|
| 9 |
-
segment_probs = preds[:, 1] # probas pour la classe "épilepsie"
|
| 10 |
-
mean_prob = np.mean(segment_probs)
|
| 11 |
-
final_label = 1 if mean_prob >= threshold else 0
|
| 12 |
-
return final_label, mean_prob, segment_probs
|
| 13 |
-
|
| 14 |
-
def predict_eeg_recording(edf_path, model, threshold=0.5):
|
| 15 |
-
preprocessed_df = preprocess_eeg_file(edf_path, fmin=1.0, fmax=45.0, segment_lenght=5, overlap=2)
|
| 16 |
-
|
| 17 |
-
if preprocessed_df is None or preprocessed_df.empty:
|
| 18 |
-
raise ValueError("EEG file could not be preprocessed or no valid segments found.")
|
| 19 |
-
|
| 20 |
-
channels = ["EEG FP1-REF", "EEG FP2-REF", "EEG F3-REF", "EEG F4-REF", "EEG C3-REF"]
|
| 21 |
-
|
| 22 |
-
spectrogram_list = preprocessed_df.apply(
|
| 23 |
-
lambda row: convert_epoch_to_spectrogram(row, channels, fs=250, nperseg=128, noverlap=64),
|
| 24 |
-
axis=1
|
| 25 |
-
).tolist()
|
| 26 |
-
|
| 27 |
-
return aggregate_predictions(spectrogram_list, model, threshold)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|