MatteoFasulo commited on
Commit
a5de583
·
verified ·
1 Parent(s): 75cce26

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +302 -9
README.md CHANGED
@@ -2,18 +2,311 @@
2
  license: cc-by-nd-4.0
3
  language:
4
  - en
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
6
- <div align="center">
7
- <h1>TinyMyo: a Tiny Foundation Model for EMG Signals at the Edge</h1>
8
- </div>
9
- <p align="center">
10
- <a href="https://creativecommons.org/licenses/by-nd/4.0/">
11
- <img src="https://img.shields.io/badge/License-CC_BY--ND_4.0-lightgrey.svg" alt="License">
12
- </a>
13
  </p>
14
 
15
- **TinyMyo** is a compact, Transformer-based **foundation model for surface EMG** signals, pre-trained on **more than 480 GB** of data drawn from multiple large-scale EMG datasets. It is optimized for **low-power, real-time signal decoding**, making it suitable for wearable and embedded applications.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  ## 🔗 Resources
18
 
19
- * **Code:** to be released following review
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: cc-by-nd-4.0
3
  language:
4
  - en
5
+ model-index:
6
+ - name: TinyMyo
7
+ results:
8
+ - task:
9
+ type: gesture-classification
10
+ dataset:
11
+ type: ninapro_db5
12
+ name: Ninapro DB5
13
+ metrics:
14
+ - name: acc@1
15
+ type: acc@1
16
+ value: 0.8941
17
+ verified: false
18
  ---
19
+
20
+ <div align="center">
21
+ <h1>TinyMyo: a Tiny Foundation Model for Flexible EMG Signal Processing at the Edge</h1>
22
+ </div>
23
+ <p align="center">
24
+ <a href="https://creativecommons.org/licenses/by-nd/4.0/"> <img src="https://img.shields.io/badge/License-CC_BY--ND_4.0-lightgrey.svg" alt="License"> </a>
 
25
  </p>
26
 
27
+ **TinyMyo** is a **3.6M-parameter** Transformer-based **foundation model for surface EMG (sEMG)**.
28
+ It is pretrained on >480 GB of EMG data and optimized for **ultra-low-power, real-time deployment**, including **microcontrollers (GAP9)** where it achieves **36.45 mW** average power consumption—the *first demonstration of an EMG foundation model running on an MCU*.
29
+
30
+ TinyMyo is built for **broad generalization** across datasets, sensor configurations, movement tasks, subjects, and domains (gesture, kinematics, speech).
31
+
32
+ ---
33
+
34
+ # 🔒 License & Usage (Model Weights)
35
+
36
+ The released TinyMyo weights are licensed under **CC BY-ND 4.0**.
37
+ This summary is not legal advice—please read the full license.
38
+
39
+ ### ✅ You may
40
+
41
+ * **Use** and **redistribute** the **unmodified** TinyMyo weights (including commercially) **with attribution**.
42
+ * **Fine-tune/modify internally** for research or production without redistributing modified weights.
43
+ * **Publish code, configs, evaluations, and papers** using TinyMyo.
44
+
45
+ ### 🚫 You may not
46
+
47
+ * **Share or host modified weights** in any form (including LoRA/adapter deltas, pruned/quantized models).
48
+ * **Claim endorsement** from the TinyMyo authors without permission.
49
+ * **Use the TinyMyo name** for derivative models.
50
+
51
+ ### 🤝 Contributing Improvements
52
+
53
+ To upstream improvements, submit a **PR** to the
54
+ **[BioFoundation repository](https://github.com/pulp-bio/BioFoundation)** with:
55
+
56
+ 1. Full reproducibility artifacts (configs, logs, seeds, environment).
57
+ 2. Evaluation on standard protocols (e.g., DB5, EPN-612, UCI EMG, DB8, Silent Speech).
58
+ 3. Comparison to TinyMyo’s reported metrics.
59
+
60
+ Approved PRs will be retrained and released as **official TinyMyo** checkpoints under CC BY-ND.
61
+
62
+ ---
63
+
64
+ # 🔎 1. Default Input & Preprocessing
65
+
66
+ Unless specified otherwise, TinyMyo expects:
67
+
68
+ * **Channels:** 16
69
+ * **Sampling rate:** 2000 Hz
70
+ * **Segment length:** 1000 samples (0.5 s)
71
+ * **Windowing:** 50% overlap (pretraining)
72
+ * **Preprocessing:**
73
+
74
+ * 4th-order **20–450 Hz bandpass**
75
+ * **50 Hz notch filter**
76
+ * **Min–max normalization** (pretraining)
77
+ * **Z-score normalization** (downstream)
78
+
79
+ Datasets with <16 channels are **zero-padded (pretraining only)**.
80
+
81
+ ---
82
+
83
+ # 🔬 2. Pretraining Overview
84
+
85
+ TinyMyo is pretrained via masked reconstruction on **three large-scale EMG datasets**:
86
+
87
+ | Dataset | Subjects | fs | Channels | Size |
88
+ | ----------- | -------- | ------- | -------- | ------- |
89
+ | Ninapro DB6 | 10 | 2000 Hz | 14 | 20.3 GB |
90
+ | Ninapro DB7 | 22 | 2000 Hz | 12 | 30.9 GB |
91
+ | EMG2Pose | 192 | 2000 Hz | 16 | 431 GB |
92
+
93
+ ## Tokenization: Channel-Independent Patches
94
+
95
+ Unlike EEG FMs that mix channels early, TinyMyo uses **per-channel patching**:
96
+
97
+ * Patch length: **20 samples**
98
+ * Patch stride: **20 samples**
99
+ * Tokens/channel: **50**
100
+ * Total seq length: **800 tokens** (16×50)
101
+ * Positional encoding: **RoPE (rotary)**
102
+
103
+ This preserves electrode-specific structure while allowing attention to learn cross-channel relationships.
104
+
105
+ ## Transformer Encoder
106
+
107
+ * **8 layers**, **3 heads**
108
+ * Embedding dim: **192**
109
+ * Pre-LayerNorm
110
+ * Dropout & drop-path: **0.1**
111
+
112
+ ## Lightweight Decoder
113
+
114
+ A **single linear layer** (~3.9k params) reconstructs masked patches.
115
+ Following SimMIM, this forces the encoder to learn robust latent structure.
116
+
117
+ ## Masking Objective
118
+
119
+ * **50% random masking** with a learnable `[MASK]` token
120
+ * Loss: **Smooth L1** with small penalty on visible patches
121
+ $$
122
+ \mathcal{L} = \mathcal{L}*{\text{masked}} + 0.1,\mathcal{L}*{\text{visible}}
123
+ $$
124
+
125
+ ## Training Setup
126
+
127
+ * Optimizer: **AdamW** (β=(0.9,0.98), wd=0.01)
128
+ * LR: **1e-4** with cosine decay
129
+ * Batch size: **512** (with grad accumulation)
130
+ * Epochs: **50**, warm-up: 10
131
+ * Hardware: **4× NVIDIA GH200 GPUs**
132
+
133
+ ---
134
+
135
+ # 🧠 3. Architecture Summary
136
+
137
+ ### Model Variant
138
+
139
+ | Variant | Params | (Layers, Dim) |
140
+ | ------- | -------- | ------------- |
141
+ | TinyMyo | **3.6M** | (8, 192) |
142
+
143
+ ---
144
+
145
+ # 🎯 4. Downstream Tasks
146
+
147
+ TinyMyo generalizes across **gesture classification**, **kinematic regression**, and **speech EMG**—with state-of-the-art or competitive results.
148
+
149
+ ---
150
+
151
+ ## 4.1 Hand Gesture Classification
152
+
153
+ Evaluated on:
154
+
155
+ * **Ninapro DB5** (52 classes, 10 subjects)
156
+ * **EPN-612** (5 classes, 612 subjects)
157
+ * **UCI EMG** (6 classes, 36 subjects)
158
+ * **Meta Neuromotor Interface** (9 gestures)
159
+
160
+ ### Preprocessing
161
+
162
+ * EMG filtering: **20–90 Hz bandpass + 50 Hz notch**
163
+ * Window sizes:
164
+
165
+ * **200 ms** (best for DB5)
166
+ * **1000 ms** (best for EPN, UCI)
167
+
168
+ ### Linear Classification Head
169
+
170
+ * Input: **C × 192**
171
+ * Params: **<40k**
172
+
173
+ ### Performance (Fine-tuned)
174
+
175
+ | Dataset | Metric | Result |
176
+ | ------------------------ | ------ | ----------------- |
177
+ | **Ninapro DB5** (200 ms) | Acc | **89.41 ± 0.16%** |
178
+ | **EPN-612** (1000 ms) | Acc | **96.74 ± 0.09%** |
179
+ | **UCI EMG** (1000 ms) | Acc | **97.56 ± 0.32%** |
180
+ | **Neuromotor** | CLER | **0.153 ± 0.006** |
181
+
182
+ TinyMyo achieves **new state-of-the-art** on DB5, EPN-612, and UCI.
183
+
184
+ ---
185
+
186
+ ## 4.2 Hand Kinematic Regression (Ninapro DB8)
187
+
188
+ * Predict **5 joint angles**
189
+ * Windows: **200 ms** or **1000 ms**
190
+ * Normalization: z-score only
191
+
192
+ ### Regression Head (~788k params)
193
+
194
+ * Depthwise + pointwise convs
195
+ * Upsampling
196
+ * Global average pooling
197
+ * Linear projection to 5 outputs
198
+
199
+ ### Performance
200
+
201
+ * **MAE = 8.77 ± 0.12°** (1000 ms)
202
+
203
+ Note: Prior works reporting ~6.9° MAE are **subject-specific**; TinyMyo trains a **single cross-subject model**, a significantly harder setting.
204
+
205
+ ---
206
+
207
+ ## 4.3 Speech Production & Recognition (Silent Speech)
208
+
209
+ Dataset: **Gaddy Silent Speech**
210
+ (8 channels, 1000 Hz, face/neck EMG)
211
+
212
+ ### Speech Production (EMG → MFCC → HiFi-GAN → Audio)
213
+
214
+ Pipeline:
215
+
216
+ 1. Residual downsampling
217
+ 2. TinyMyo encoder
218
+ 3. Linear projection → **26-dim MFCC**
219
+ 4. HiFi-GAN vocoder
220
+
221
+ **WER:** **33.54 ± 1.12%**
222
+ ≈ state-of-the-art with **>90% fewer params** in the transduction model.
223
+
224
+ ### Speech Recognition (EMG → Text)
225
+
226
+ * TinyMyo encoder
227
+ * Linear projection → **37 characters**
228
+ * **CTC** loss
229
+ * 4-gram LM + beam search
230
+
231
+ **WER:** **33.95 ± 0.97%**
232
+
233
+ TinyMyo is EMG-only—unlike multimodal systems like MONA-LISA.
234
+
235
+ ---
236
+
237
+ # ⚡ 5. Edge Deployment (GAP9 MCU)
238
+
239
+ TinyMyo runs efficiently on **GAP9 (RISC-V)** via:
240
+
241
+ * **INT8 quantization**, including attention
242
+ * Multi-level streaming (L3→L2→L1)
243
+ * Integer LayerNorm, GELU, softmax
244
+ * Static memory arena via liveness analysis
245
+
246
+ ### Runtime (DB5 pipeline)
247
+
248
+ * **Inference time:** 12.2 s
249
+ * **Energy:** 0.44 J
250
+ * **Average power:** **36.45 mW**
251
+
252
+ This is the **first EMG foundation model demonstrated on a microcontroller**.
253
+
254
+ ---
255
+
256
+ # 📊 6. Results Summary
257
+
258
+ ### Pretraining
259
+
260
+ * Smooth L1 reconstruction with high fidelity
261
+ * Total compute ≈ **4.0 GFLOPs**
262
+
263
+ ### Downstream Highlights
264
+
265
+ * **DB5:** 89.41%
266
+ * **EPN-612:** 96.74%
267
+ * **UCI EMG:** 97.56%
268
+ * **Neuromotor:** 0.153 CLER
269
+ * **DB8 Regression:** MAE 8.77°
270
+ * **Silent Speech Production:** 33.54% WER
271
+ * **Silent Speech Recognition:** 33.95% WER
272
+
273
+ TinyMyo matches or exceeds state-of-the-art performance—while being smaller and more efficient than all prior EMG foundation models.
274
+
275
+ ---
276
+
277
+ # 🛠️ Code & Usage
278
+
279
+ To fine-tune TinyMyo on downstream tasks, follow the examples in the
280
+ **[BioFoundation repository](https://github.com/pulp-bio/BioFoundation)**.
281
+
282
+ ```bash
283
+ python -u run_train.py +experiment=TinyMyo_finetune \
284
+ pretrained_safetensors_path=/path/to/model.safetensors
285
+ ```
286
+
287
+ Environment variables:
288
+
289
+ * `DATA_PATH` → dataset path
290
+ * `CHECKPOINT_DIR` → checkpoint to load
291
+
292
+ ---
293
 
294
  ## 🔗 Resources
295
 
296
+ - **Code:** https://github.com/pulp-bio/BioFoundation
297
+
298
+ ---
299
+
300
+ # 📜 Citation
301
+
302
+ Please cite TinyMyo using:
303
+
304
+ ```bibtex
305
+ ```
306
+
307
+ ---
308
+
309
+ # 🧭 Contact & Support
310
+
311
+ * Questions or issues?
312
+ Open an issue on the **BioFoundation GitHub repository**.