This repository contains the public model release of our paper: "Exploring pattern-specific components associated with hand gestures through different sEMG measures" and "Understanding of task-specific and subject-specific components in surface EMG".
Surface electromyography (sEMG)-based gesture recognition is widely used in human-machine interaction (HMI), prosthetic control, wearable interfaces, and rehabilitation systems. However, conventional gesture recognition models often suffer from poor cross-subject generalization, since sEMG signals contain strong subject-specific variations caused by differences in physiology, muscle contraction habits, and electrode placement.
This work proposes that sEMG signals consist of two disentangled components:
-
Pattern-specific components
Shared across users and associated only with gesture patterns. -
Subject-specific components
Related to individual physiological characteristics and recording variations.
To separate these two components, we propose a GAN-enhanced disentanglement framework based on a multi-encoder autoencoder architecture. The extracted pattern-specific components are then used for generalized gesture recognition in cross-subject scenarios.
We introduce a disentanglement framework that separates:
- gesture-related information
- subject-related information
from high-density sEMG signals using:
- dual encoders
- shared decoder
- adversarial discriminator (GAN)
This allows the system to learn gesture representations that are more invariant across users.
The extracted pattern-specific components are reconstructed into spatial heatmaps aligned with the electrode topology, enabling visualization of muscle activation patterns during gestures.
The resulting heatmaps show:
- similarity across subjects
- clear differences across gestures
- correspondence with forearm muscle activation regions
This provides neurophysiological interpretability for the learned representations.
The proposed framework consists of:
- Pattern-specific encoder (
Ep) - Subject-specific encoder (
Es) - Shared decoder (
D) - GAN discriminator
The training objective includes triplet loss, reconstruction loss, cross-reconstruction loss, and adversarial loss.
Experiments were conducted on the open-source Hyser HD-sEMG dataset.
- 20 subjects
- 256-channel HD-sEMG
- 10 hand gestures
- 2048 Hz sampling rate
- 4 electrode arrays (8Γ8 each)
- dynamic gesture tasks only
| Input Measure | Best Accuracy |
|---|---|
| Raw Signal | 52.61% |
| sEMG Envelope | 67.52% |
| STFT | 79.41% |
| RMS | 74.41% |
| WL | 76.23% |
| All Time-Domain Features | 82.51% |
| STFT + Time-Domain Features | 84.30% |
The reconstructed heatmaps demonstrate:
- compact and gesture-specific activation regions
- cross-subject consistency
- physiologically meaningful muscle activation localization
Compared with waveform inputs, STFT and time-domain features produce more discriminative and interpretable gesture patterns.
step0_main_code.py: train/test the disentanglement model and export latent.npzfiles.data_module.py: PyTorch Lightning data modules for subject/session splits.models.py: encoder, decoder, Lightning model, latent export, and classifier model definitions.step1_test_classifier.py: evaluate latent features withknn,svm,rf,ann,cnn, orlstm.step2_confusion_array_plot.py: plot reconstruction correlation heatmap.step3_generate_latent_plot.py: regenerate/plot latent reconstruction maps from saved models.step4_Statistical_Analysis.py: statistical comparison of classifier accuracy files.run_pipeline.sh: complete train, test, and classifier workflow.
conda create -n hand_dt python=3.10
conda activate hand_dt
pip install -r requirements.txtThe original code targets pytorch-lightning==1.9.4. Install a CUDA-compatible PyTorch build for your machine if the default pip install torch is not suitable.
Each preprocessed data folder should contain subject/session folders:
DATA_ROOT/
PR_v1_features_half_unslice_repair/
subject01_session1/
pr_feature_smooth_dynamic.mat
label_dynamic.mat
subject01_session2/
pr_feature_smooth_dynamic.mat
label_dynamic.mat
settings.py maps --data_type to these folder names. You can either pass --data_root /path/to/DATA_ROOT or bypass the mapping with --data_dir /path/to/specific/preprocessed/folder.
step0_main_code.py:
--root_dir: output root for models, logs, plots, and latent features. Default:./runs.--data_root: root of preprocessed data folders. Default can be set withHAND_DT_DATA_ROOT.--data_dir: explicit data folder; overrides--data_root.--trail_id: experiment id used in output paths. The name is kept for compatibility with existing results.--test_id: test subject ids, e.g.--test_id 1 5 9.--session_id: session id used as the training session; the other session is used for testing byDataModule_session.--data_type: one ofresample171_data_half,smooth_rms_half,unslice_features_half,stft_half,StftFeature.--features: feature indices for custom feature-set runs.--decoder_type:vaeororig.--purpose:train,test,test_trainset, ortest_allset.--accelerator:gpu,cpu, orauto.--devices: device ids for Lightning, e.g.--devices 0or--devices 0 1.--batch_size,--num_workers,--max_epochs,--lr,--weight_decay: training hyperparameters.--lamda1,--lamda2: loss weights for triplet and cross-reconstruction terms.
step1_test_classifier.py:
--root_dir: same output root used bystep0_main_code.py.--trial_id: one or more trial ids. Multiple trials concatenate latent features.--test_id,--session_id: subjects and sessions to evaluate.--purpose:pfor gesture/pattern latentxp,sfor subject latentxs.--methods: classifier list, e.g.--methods knn rf svm.--latent_dim: flattened latent branch dimension. Default512.
Edit environment variables as needed, then run:
chmod +x run_pipeline.sh
ROOT_DIR=./runs \
DATA_ROOT=/nas/data_EMG/data_DT \
TRIAL_ID=5 \
DATA_TYPE=unslice_features_half \
TEST_IDS="1" \
SESSION_ID=1 \
DEVICE_IDS="0" \
./run_pipeline.shEquivalent manual commands:
python step0_main_code.py --root_dir ./runs --data_root /nas/data_EMG/data_DT --trail_id 5 --test_id 1 --session_id 1 --data_type unslice_features_half --purpose train --accelerator gpu --devices 0
python step0_main_code.py --root_dir ./runs --data_root /nas/data_EMG/data_DT --trail_id 5 --test_id 1 --session_id 1 --data_type unslice_features_half --purpose test --accelerator gpu --devices 0
python step1_test_classifier.py --root_dir ./runs --trial_id 5 --test_id 1 --session_id 1 --purpose p --methods knnOutputs are written under ROOT_DIR/models, ROOT_DIR/latent_features, and ROOT_DIR/outputs.
If you find this work useful, please cite:
@article{yuan2024exploring,
title={Exploring pattern-specific components associated with hand gestures through different sEMG measures},
author={Yuan, Yangyang and Liu, Jionghui and Dai, Chenyun and Liu, Xiao and Hu, Bo and Fan, Jiahao},
journal={Journal of neuroengineering and rehabilitation},
volume={21},
number={1},
pages={233},
year={2024},
publisher={Springer}
}
@article{yuan2025understanding,
title={Understanding of task-specific and subject-specific components in surface EMG},
author={Yuan, Yangyang and Liu, Jionghui and Jiang, Xinyu and Fan, Jiahao and Chou, Chih-Hong and Dai, Chenyun},
journal={International Journal of Neural Systems},
volume={35},
number={09},
pages={2550046},
year={2025},
publisher={World Scientific}
}For questions or collaborations, please contact:
- Yangyang Yuan β yyyuan25@sjtu.edu.cn


