-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict.py
More file actions
35 lines (27 loc) · 1.12 KB
/
Copy pathpredict.py
File metadata and controls
35 lines (27 loc) · 1.12 KB
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
import numpy as np
import tensorflow as tf
from data_loader import EEGDataLoader
from preprocessing import EEGPreprocessor
from feature_extraction import EEGFeatureExtractor
from utils import load_model_checkpoint
# Load training model
MODEL_PATH = "cnn_crf_model.h5"
model = load_model_checkpoint(MODEL_PATH)
def predict_sleep_stage(eeg_data):
# Preprocess EEG data
preprocessor = EEGPreprocessor(sampling_rate=100)
processed_data = preprocessor.preprocess(eeg_data)
# Extract features
feature_extractor = EEGFeatureExtractor(sampling_rate=100)
features = feature_extractor.extract_features(processed_data)
# Make predictions
predictions = np.argmax(model.predict(features), axis=-1)
# Sleep stage mapping
sleep_stages = ["Wake", "N1", "N2", "N3", "REM"]
predicted_stages = [sleep_stages[p] for p in predictions]
return predicted_stages
if __name__ == "__main__":
# Simulate a single EEG sample (300 time points, 100 features)
dummy_eeg_data = np.random.randn(1, 3000)
predicted_stages = predict_sleep_stage(dummy_eeg_data)
print("Predicted Sleep Stages:", predicted_stages)