emilelemoine commited on
Commit
93f12e7
·
verified ·
1 Parent(s): df7c8ce

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +96 -3
README.md CHANGED
@@ -1,3 +1,96 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: eegzoo
4
+ tags:
5
+ - eeg
6
+ - epilepsy
7
+ - neuroscience
8
+ - vision-transformer
9
+ ---
10
+
11
+ # DeepEpilepsy V2
12
+
13
+ Spectrogram-based Vision Transformer (SimpleViT) for EEG representation learning.
14
+ Produces 512-dimensional embeddings from 60-second, 19-channel EEG segments in the 10-20 referential montage.
15
+
16
+ ## Checkpoints
17
+
18
+ | File | Params | Layers | Heads | Training data |
19
+ |------|--------|--------|-------|---------------|
20
+ | `deepepilepsy_v2_large.pt` | 14M | 4 | 4 | CHUM epilepsy (supervised) |
21
+ | `deepepilepsy_v2_huge.pt` | 23M | 6 | 8 | CHUM epilepsy (supervised) |
22
+ | `deepepilepsy_v2_large_tuh.pt` | 14M | 4 | 4 | TUH abnormal (pretrained) |
23
+ | `deepepilepsy_v2_huge_tuh.pt` | 27M | 8 | 8 | TUH abnormal (pretrained) |
24
+
25
+ > **Note:** The TUH huge checkpoint uses 8 encoder layers (not 6), so it does not load into the default `DeepEpilepsyV2Huge` adapter.
26
+
27
+ ## Usage with eegzoo
28
+
29
+ ```bash
30
+ pip install eegzoo[spectral] # MNE required for spectrogram preprocessing
31
+ ```
32
+
33
+ ```python
34
+ from eegzoo import get
35
+
36
+ model = get("deepepilepsy_v2_large", weights="emilelemoine/DeepEpilepsy_V2")
37
+
38
+ tensor = model.preprocess(segment, sfreq=256, channel_names=ch_names) # (19, 32, 3000)
39
+ embeddings = model.embed(tensor.unsqueeze(0)) # (1, 512)
40
+ ```
41
+
42
+ To load a non-default checkpoint (e.g. TUH large):
43
+
44
+ ```python
45
+ model = get(
46
+ "deepepilepsy_v2_large",
47
+ weights="emilelemoine/DeepEpilepsy_V2/deepepilepsy_v2_large_tuh.pt",
48
+ )
49
+ ```
50
+
51
+ ## Architecture
52
+
53
+ ```
54
+ Conv2dTokenizer (19, 32, 3000) -> (batch, 60, 512)
55
+ 3x strided Conv2d(freq_kernel=3, time_kernel=11, stride=(2,1))
56
+ + Conv2d(4, 1, stride=(1, 50)) # collapse freq, stride time
57
+ Sinusoidal positional encoding (1D, not learned)
58
+ TransformerEncoder
59
+ N x [LayerNorm -> MultiheadAttention -> LayerNorm -> MLP]
60
+ Final LayerNorm
61
+ Mean pooling -> 512-dim embedding
62
+ Linear(512, 2) classification head (not used for embeddings)
63
+ ```
64
+
65
+ Intermediate tokenizer channel widths are geometrically interpolated from `dim_internal` to `dim_hidden`:
66
+
67
+ | Variant | dim_internal | Channels | dim_mlp |
68
+ |---------|-------------|----------|---------|
69
+ | Large | 128 | 128 -> 256 -> 512 | 768 |
70
+ | Huge | 256 | 256 -> 362 -> 512 | 1024 |
71
+
72
+ ## Preprocessing
73
+
74
+ 1. Select and reorder 19 channels (Fp1, Fp2, F3, F4, C3, C4, P3, P4, F7, F8, T3, T4, T5, T6, O1, O2, Fz, Cz, Pz)
75
+ 2. Resample to 200 Hz
76
+ 3. Crop to 12,000 samples (60s)
77
+ 4. Morlet wavelet spectrogram:
78
+ - 60 Hz notch filter (FIR)
79
+ - Morlet CWT: 32 log-spaced frequencies (0.2--100 Hz), 7 cycles, decim=4
80
+ - Log transform: `log(power + 1e-9)`
81
+ - Robust normalization: `(x - median) / (Q75 - Q25 + 1e-9)` (global)
82
+ 5. Output shape: `(19, 32, 3000)`
83
+
84
+ ## State dict format
85
+
86
+ Clean `state_dict` (no `module.` prefix, no optimizer state). Keys follow torchvision naming:
87
+
88
+ ```
89
+ stem.layers.conv_stem_{0,1,2}.{0,2}.{weight,bias}
90
+ stem.layers.conv_last.{weight,bias}
91
+ encoder.layers.encoder_layer_{N}.{ln_1,self_attention,ln_2,mlp}.*
92
+ encoder.ln.{weight,bias}
93
+ mlp_head.{weight,bias}
94
+ ```
95
+
96
+ `pos_embedding` is not stored (deterministic sinusoidal, recomputed at init).