Convolutional Block Attention Module for Hand Gesture recognition by sEMG.
main/
│
├── checkpoints # Weights from all trials
│ └── ...
│
├── emg_recorder
│ ├── data # Real datasets
│ │ ├── continuous/
│ │ └── discrete/
│ ├── model_finetuned/ # Weights and standatrizaion parameters for best model
│ ├── notebooks/
│ │ ├── emg_analysis_continuous.ipynb # FIXME
│ │ └── emg_analysis_discrete.ipynb # Fine-tuning
│ ├── myo_serial.py # Some script from pyomyo
│ ├── realtime.py # Real-time inference
│ ├── record_emgs_contin.py
│ └── record_emgs_discrete.py
│
├── Ninapro_DB5/
│
├── normalization_values/ # Standartization parameters
│ └── *.json
│
├── reports/ # FIXME: plots
│
├── src
│ ├── `__init__.py`
│ ├── dataset.py # Functions for parsing and preprocessing
│ ├── models.py # All models
│ ├── train_kfold.py # K-fold validation trials
│ └── train.py # FIXME: single model train
│
├── trial_scripts/ # Experimental trials
│
├── .gitignore
├── config_recorder.py # EMG recorder app parameters
├── config.py # Model and training hyperparameters
├── README.md
├── requirements.txt # Model hyperparameters
└── utils.py # Additional functions
- Python 3.10.12
- bleak 0.19.5
- Numpy 1.23.5
- Tensorflow 2.12.0
- MLFlow 3.1.1
Installation:
pip install -r requirements.txt
Here is algorithm how to get fine-tuned model based on your own sEMG signals:
-
Obtain signals in two ways:
1.1. Run
record_emgs_discrete.pyto collectNarrays of the gestures. For example if you runpython record_emgs_discrete.py --gesture 0you would collect signals for the rest.1.2. Run
record_emgs_contin.pyto collect the continuous array of the gestures.
Important
It's recommended to use the first option.
-
Then run the appropriate notebook in
emg_recorder/notebooks/to fine-tune the baseline model. Also you can check the performance. -
Finally, run
realtime.py.
DB5 - this Ninapro dataset includes sEMG and kinematic data from 10 intact subjects while repeating 52 hand movements plus the rest position. The dataset is described in detail in the following scientific paper:
There are 9 gestures and 10 subjects in dataset for training. The set of the gestures consist of:
0- Rest13- Thumb up15- Flexion of ring and little finger, extension of the others18- fingers flexed together in fist19- Pointing index34- Medium wrap38- Writing tripod grasp43- Prismatic pinch grasp46- Lateral grasp
The model is a lightweight 2D convolutional neural network designed for classifying surface EMG signals into predefined hand gestures.
It takes a sliding window of WINDOW_SIZE samples from 8 EMG channels as input. To improve spatial and channel-wise feature selection, the model incorporates a Spatial Attention Module (SAM) after convolutional encoder.
The Spatial Attention Module focuses on "where" the most informative features are located by generating a spatial attention map. It complements channel attention by emphasizing important regions along the temporal or spatial dimensions of the feature map.
The final classification layer outputs softmax probabilities across the gesture classes.
Training is performed using the categorical cross-entropy loss and the Adam optimizer, with real-time logging via MLflow.
Moreover, there is Channel Attention Module (CAM) implemented in baseline. The main goal of CAM is the analysis of the channel importance.
add: new function/model
feat: new feature
fix: bugs
docs: documentation, description
refactor: refactoring
chore: dependency update, build
minor
This project is licensed under the terms of the GNU General Public License v3.0 (GPLv3).
You are free to use, modify, and distribute this code, but any derivative work must also be open-sourced under the same license.
See the LICENSE file for full license text.


