File size: 3,852 Bytes
9c3fd5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f71d8ee
 
 
 
9c3fd5e
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
language: en
tags:
  - emg
  - gesture-recognition
  - prosthetic-hand
  - cnn-lstm
  - myo-armband
  - quick-calibration
  - real-time
license: mit
---

# EMG Hand Control β€” Prosthetic Hand Gesture Recognition

Real-time EMG-based hand gesture recognition for prosthetic arm control using CNN+LSTM with Quick Calibration. Works for any new user after ~2 minutes of calibration.

## Performance

| Gesture | Accuracy (Self) | Accuracy (New User after Calibration) |
|---------|----------------|---------------------------------------|
| rest | 100% | ~85% |
| fist | 100% | ~85% |
| grasp | 99% | ~80% |
| index | 97% | ~75% |
| middle | 100% | ~85% |
| ring | 100% | ~85% |
| pinky | 95% | ~75% |
| thumb | 100% | ~85% |
| wrist_rotate_out | 92% | ~80% |
| wrist_rotate_in | 90% | ~80% |
| **Overall** | **97.2%** | **~85%** |

## Architecture
Input: 150 samples Γ— 8 EMG channels (750ms @ 200Hz)
↓
CNN Block:
Conv1D(64)  β†’ BatchNorm β†’ ReLU
Conv1D(128) β†’ BatchNorm β†’ ReLU β†’ MaxPool β†’ Dropout(0.3)
Conv1D(256) β†’ BatchNorm β†’ ReLU β†’ MaxPool β†’ Dropout(0.3)
↓
Bidirectional LSTM (hidden=128, layers=2, dropout=0.3)
↓
FC: Dense(128) β†’ ReLU β†’ Dropout(0.4) β†’ Dense(10)
↓
Output: 10 gesture classes

## Quick Calibration System

New user calibration in ~2 minutes:

User wears Myo Armband
Performs each gesture 3 times Γ— 5 seconds
System fine-tunes last layer on user data (30s)
Ready β€” no full retraining needed


## Gestures

| Label | Gesture |
|-------|---------|
| 0 | rest |
| 1 | fist |
| 2 | grasp (cylindrical grip) |
| 3 | index finger extension |
| 4 | middle finger extension |
| 5 | ring finger extension |
| 6 | pinky finger extension |
| 7 | thumb extension |
| 8 | wrist rotate out (pronation) |
| 9 | wrist rotate in (supination) |

## Dataset

- 4 personal recording sessions
- 10 gestures Γ— 10 rounds Γ— 5 seconds each
- ~400,000 EMG samples
- Myo Armband β€” 8 channels β€” 200Hz

## Training Details

| Parameter | Value |
|-----------|-------|
| Window | 150 samples (750ms) |
| Step | 75 samples (50% overlap) |
| Optimizer | AdamW (lr=5e-4) |
| Loss | Weighted CrossEntropy + Label Smoothing |
| Epochs | 100 (best at epoch 78) |
| Batch size | 128 |
| Normalization | Global fixed (saved as .npy files) |

## Key Technical Contributions

1. **Block-level train/test split** β€” prevents data leakage from overlapping windows
2. **Fixed global normalization** β€” ensures train/inference consistency (critical fix that improved accuracy from 2% to 94% on rest gesture)
3. **Quick calibration via last-layer fine-tuning** β€” enables cross-user generalization without full retraining
4. **Hysteresis voting** β€” stable real-time predictions for actuator control

## Files

| File | Description |
|------|-------------|
| `models/best_model_hand.pt` | Trained PyTorch weights |
| `models/hand_norm_mean.npy` | Global normalization mean |
| `models/hand_norm_std.npy` | Global normalization std |
| `code/train_hand.py` | Training pipeline |
| `code/quick_calibration.py` | Calibration + real-time inference |
| `code/collect_hand_data.py` | Guided data collection |

## Usage

```python
# Quick Calibration for new user
python3 quick_calibration.py
# Records 2 min β†’ fine-tunes β†’ real-time inference
```

## Hardware

- Sensor: Myo Armband (8 EMG channels, 200Hz, Bluetooth)
- Controller: Raspberry Pi (deployment)
- Prosthetic: 3D-printed hand with servo motors + tendon system
- Communication: Serial (115200 baud)

## Related

- Drone Control Model: [malansi/EMG-Gesture-Recognition](https://huggingface.co/malansi/EMG-Gesture-Recognition)
- Dataset: [malansi/EMG-Gesture-Dataset](https://huggingface.co/datasets/malansi/EMG-Gesture-Dataset)

## Demo

https://youtube.com/shorts/JOfaNj-Af6Q

## Author

Mohammed Alansi
AI & Biomechatronics Research β€” EMG-Based Prosthetic Arm Control