shamiquekhan commited on
Commit
8a2df2a
·
1 Parent(s): 49ebf4e

SEO: full metadata, safetensors, model-index, cross-links, front-loaded metrics

Browse files
Files changed (2) hide show
  1. README.md +99 -72
  2. student_full_finetuned.safetensors +3 -0
README.md CHANGED
@@ -1,23 +1,97 @@
1
  ---
2
  license: cc-by-4.0
3
  library_name: pytorch
 
4
  tags:
5
  - sleep-staging
6
  - polysomnography
7
  - eeg
8
  - eog
9
  - emg
 
 
 
 
 
 
 
 
 
 
 
 
10
  - sleep-edf
11
- - biomedical
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
  # NeuroSleep — Light-Weight Sleep Stage Model
15
 
16
- ## Model Summary
17
 
18
- A compact PyTorch model for five-stage sleep-stage classification from four-channel polysomnography (PSG) signals. Processes 300 seconds of context (10 x 30-second epochs) and classifies each epoch into Wake, N1, N2, N3, or REM.
19
 
20
- 99,477 parameters designed for edge deployment.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  ## Architecture
23
 
@@ -53,6 +127,7 @@ Wake / N1 / N2 / N3 / REM
53
  - **Epoch length:** 30 seconds (3000 samples)
54
  - **Sequence length:** 10 epochs
55
  - **Shape:** `[batch, 10, 4, 3000]`
 
56
 
57
  ## Output Labels
58
 
@@ -83,65 +158,12 @@ Wake / N1 / N2 / N3 / REM
83
  | N3 | 0.877 | 0.845 | 0.912 |
84
  | REM | 0.808 | 0.714 | 0.930 |
85
 
86
- > **Note:** N1 and REM have lower precision because the model over-predicts these transitional stages. This is expected given physiological overlap with Wake and N2.
87
-
88
- ## How to Use
89
-
90
- ### Installation
91
-
92
- ```bash
93
- pip install torch numpy
94
- ```
95
-
96
- ### Load the Model
97
-
98
- ```python
99
- import torch
100
- import sys
101
- from huggingface_hub import hf_hub_download
102
-
103
- # Download checkpoint
104
- path = hf_hub_download(
105
- repo_id="shamique/Light-Weight-Neuromorphic-Sleep-Stage-Model",
106
- filename="student_full_finetuned.pt",
107
- )
108
-
109
- # Define the model class (from the source repo)
110
- # You need the ImprovedStudent class — see: https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline
111
- from sleep_staging.models.improved_student import ImprovedStudent
112
-
113
- model = ImprovedStudent()
114
- model.load_state_dict(torch.load(path, map_location="cpu", weights_only=True))
115
- model.eval()
116
- ```
117
-
118
- ### Run Inference
119
-
120
- ```python
121
- import numpy as np
122
-
123
- # Dummy input: 1 batch, 10 epochs, 4 channels, 3000 samples each
124
- # Replace with real preprocessed PSG data (100 Hz, bandpass filtered, z-score normalized)
125
- x = torch.randn(1, 10, 4, 3000)
126
 
127
- with torch.no_grad():
128
- logits = model(x) # [1, 10, 5]
129
- probs = torch.softmax(logits, dim=-1)
130
- preds = probs.argmax(dim=-1) # [1, 10]
131
-
132
- # Stage names
133
- STAGE_NAMES = {0: "Wake", 1: "N1", 2: "N2", 3: "N3", 4: "REM"}
134
-
135
- # Print prediction for each epoch
136
- for i in range(10):
137
- stage = STAGE_NAMES[preds[0, i].item()]
138
- conf = probs[0, i, preds[0, i]].item()
139
- print(f"Epoch {i}: {stage} (confidence: {conf:.3f})")
140
- ```
141
-
142
- ### Preprocessing Required
143
 
144
  The model expects preprocessed data:
 
145
  1. **Bandpass filter:** 0.5–35 Hz
146
  2. **Notch filter:** 50 Hz
147
  3. **Normalization:** z-score per channel
@@ -149,11 +171,20 @@ The model expects preprocessed data:
149
 
150
  See the [source repo](https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline) for the full preprocessing pipeline.
151
 
 
 
 
 
 
 
 
 
 
152
  ## Intended Use
153
 
154
  - Research and educational sleep-stage classification
155
  - Benchmarking and comparison with other sleep staging methods
156
- - Edge deployment on resource-constrained devices
157
 
158
  ## Limitations
159
 
@@ -162,18 +193,14 @@ See the [source repo](https://github.com/shamiquekhan/neuromorphic-sleep-staging
162
  - Trained on Sleep-EDF Expanded (15 subjects); generalizability should be validated
163
  - Requires 4-channel PSG (Fpz-Cz, Pz-Oz, EOG, EMG) — single-channel EEG not supported
164
 
165
- ## Training Details
166
-
167
- - **Dataset:** Sleep-EDF Expanded (15 subjects, PhysioNet)
168
- - **Optimizer:** AdamW (lr=3e-4, weight_decay=1e-2)
169
- - **Epochs:** 15
170
- - **Class weights:** N1=2x, REM=2x
171
- - **Supervision:** All-position (every epoch in 10-epoch window)
172
- - **Gradient clipping:** max_norm=1.0
173
-
174
- ## Source
175
 
176
- - **GitHub:** [neuromorphic-sleep-staging-pipeline](https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline)
 
 
 
 
 
177
 
178
  ## Citation
179
 
 
1
  ---
2
  license: cc-by-4.0
3
  library_name: pytorch
4
+ pipeline_tag: time-series-classification
5
  tags:
6
  - sleep-staging
7
  - polysomnography
8
  - eeg
9
  - eog
10
  - emg
11
+ - biosignals
12
+ - signal-processing
13
+ - time-series
14
+ - healthcare
15
+ - medical
16
+ - edge-ai
17
+ - tinyml
18
+ - on-device
19
+ - gru
20
+ - cnn
21
+ - depthwise-separable-convolution
22
+ - gabor-filter
23
  - sleep-edf
24
+ - physionet
25
+ - lightweight
26
+ - low-parameter
27
+ datasets:
28
+ - siamakz/sleep_edf_expanded
29
+ model-index:
30
+ - name: NeuroSleep Improved Student
31
+ results:
32
+ - task:
33
+ type: time-series-classification
34
+ name: Sleep Stage Classification
35
+ dataset:
36
+ type: sleep-edf-expanded
37
+ name: Sleep-EDF Expanded (15 subjects)
38
+ metrics:
39
+ - type: accuracy
40
+ value: 0.930
41
+ name: Accuracy
42
+ - type: kappa
43
+ value: 0.861
44
+ name: Cohen's Kappa
45
+ - type: f1
46
+ value: 0.794
47
+ name: Macro F1
48
+ - type: f1
49
+ value: 0.935
50
+ name: Weighted F1
51
  ---
52
 
53
  # NeuroSleep — Light-Weight Sleep Stage Model
54
 
55
+ **99,477 parameters, 93% accuracy (κ=0.86) — small enough for edge/wearable deployment, scoring Wake/N1/N2/N3/REM from 4-channel PSG.**
56
 
57
+ > **Quick links:** [GitHub](https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline) · [Live Demo](https://huggingface.co/spaces/shamique/neurosleep-demo) · [Kaggle](https://www.kaggle.com/shamiquekhan/neurosleep-final)
58
 
59
+ A compact PyTorch model for five-stage sleep-stage classification from polysomnography signals. Processes 300 seconds of context (10 × 30-second epochs) and classifies each epoch into Wake, N1, N2, N3, or REM. Designed for edge deployment on resource-constrained devices.
60
+
61
+ ## Quick Start
62
+
63
+ ```python
64
+ import torch
65
+ from huggingface_hub import hf_hub_download
66
+ from safetensors.torch import load_file
67
+
68
+ # Download checkpoint
69
+ path = hf_hub_download(
70
+ repo_id="shamique/Light-Weight-Neuromorphic-Sleep-Stage-Model",
71
+ filename="student_full_finetuned.safetensors",
72
+ )
73
+
74
+ # Load model (see source repo for ImprovedStudent class definition)
75
+ # https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline
76
+ from sleep_staging.models.improved_student import ImprovedStudent
77
+
78
+ model = ImprovedStudent()
79
+ model.load_state_dict(load_file(path, device="cpu"))
80
+ model.eval()
81
+
82
+ # Run inference on preprocessed PSG data
83
+ # Input: [batch, 10, 4, 3000] — 10 epochs, 4 channels, 3000 samples @ 100Hz
84
+ x = torch.randn(1, 10, 4, 3000) # replace with real data
85
+
86
+ with torch.inference_mode():
87
+ logits = model(x) # [1, 10, 5]
88
+ probs = torch.softmax(logits, dim=-1)
89
+ preds = probs.argmax(dim=-1) # [1, 10]
90
+
91
+ STAGE_NAMES = {0: "Wake", 1: "N1", 2: "N2", 3: "N3", 4: "REM"}
92
+ for i in range(10):
93
+ print(f"Epoch {i}: {STAGE_NAMES[preds[0, i].item()]} ({probs[0, i, preds[0, i]].item():.2%})")
94
+ ```
95
 
96
  ## Architecture
97
 
 
127
  - **Epoch length:** 30 seconds (3000 samples)
128
  - **Sequence length:** 10 epochs
129
  - **Shape:** `[batch, 10, 4, 3000]`
130
+ - **Preprocessing:** 0.5–35 Hz bandpass → 50 Hz notch → z-score normalization
131
 
132
  ## Output Labels
133
 
 
158
  | N3 | 0.877 | 0.845 | 0.912 |
159
  | REM | 0.808 | 0.714 | 0.930 |
160
 
161
+ > **Note:** N1 and REM have lower precision because the model over-predicts these transitional stages, which is expected given physiological overlap with Wake and N2.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
+ ## Preprocessing
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  The model expects preprocessed data:
166
+
167
  1. **Bandpass filter:** 0.5–35 Hz
168
  2. **Notch filter:** 50 Hz
169
  3. **Normalization:** z-score per channel
 
171
 
172
  See the [source repo](https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline) for the full preprocessing pipeline.
173
 
174
+ ## Training Details
175
+
176
+ - **Dataset:** Sleep-EDF Expanded (15 subjects, PhysioNet)
177
+ - **Optimizer:** AdamW (lr=3e-4, weight_decay=1e-2)
178
+ - **Epochs:** 15
179
+ - **Class weights:** N1=2x, REM=2x
180
+ - **Supervision:** All-position (every epoch in 10-epoch window)
181
+ - **Gradient clipping:** max_norm=1.0
182
+
183
  ## Intended Use
184
 
185
  - Research and educational sleep-stage classification
186
  - Benchmarking and comparison with other sleep staging methods
187
+ - Edge deployment on resource-constrained devices (MCUs, wearables)
188
 
189
  ## Limitations
190
 
 
193
  - Trained on Sleep-EDF Expanded (15 subjects); generalizability should be validated
194
  - Requires 4-channel PSG (Fpz-Cz, Pz-Oz, EOG, EMG) — single-channel EEG not supported
195
 
196
+ ## Resources
 
 
 
 
 
 
 
 
 
197
 
198
+ | Resource | Link |
199
+ |----------|------|
200
+ | **Source Code** | [GitHub](https://github.com/shamiquekhan/neuromorphic-sleep-staging-pipeline) |
201
+ | **Live Demo** | [Hugging Face Space](https://huggingface.co/spaces/shamique/neurosleep-demo) |
202
+ | **Reproduce** | [Kaggle Notebook](https://www.kaggle.com/shamiquekhan/neurosleep-final) |
203
+ | **Model Weights** | This page |
204
 
205
  ## Citation
206
 
student_full_finetuned.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71019269054c170b468735af3536d085b3753879ac5f9a6b9ce64eb18370ab0d
3
+ size 401684