Skip to content

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Uncertainty-Aware Single-Channel Surface EMG Classification for Low-Resource Hand Gesture Recognition

Python PyTorch License: MIT

Official implementation for the paper:

Uncertainty-Aware Single-Channel Surface EMG Classification for Low-Resource Hand Gesture Recognition: A Subject-Independent Evaluation
Yiğit Aydoğan, İsmail Cantürk
Medical & Biological Engineering & Computing (under review)


Overview

This repository contains the complete analysis and publication-figure pipeline for the paper. The study evaluates five-class hand gesture classification using a single Flexor Carpi Radialis (FCR) surface EMG electrode, representing a low-resource clinical deployment scenario. It investigates whether uncertainty-aware selective prediction can improve the reliability of subject-independent classification without subject-specific calibration.

Key findings:

  • The best within-subject accuracy is 73.3% with Random Forest
  • MC Dropout achieves 55.3% full-coverage LOSOCV accuracy
  • MC Dropout selective prediction reaches 73.0% accuracy at 50% coverage without subject-specific calibration
  • Per-subject MC Dropout uncertainty predicts generalisation failure on the YTU dataset (r=-0.350)
  • External validation on NinaPro DB2 confirms the uncertainty–accuracy relationship across 40 independent subjects (r=-0.477)
  • Deep Ensembles provide the best calibration, while Evidential Deep Learning (EDL) fails because of vacuity collapse on low-dimensional tabular features

Repository Components

Component Purpose
emg_unified_v5.py Main YTU analysis pipeline, including preprocessing, quality screening, classifiers, uncertainty methods, statistical analysis, and saved result tables
ninapro_validation_v2.py Standalone NinaPro DB2 external-validation pipeline
Publication Figure Generation — Revision Standalone script that regenerates all six manuscript figures and one additional ablation heatmap from the saved CSV outputs
README.md Repository documentation

Scripts

emg_unified_v5.py — Main Pipeline

A self-contained script that runs the complete analysis on the YTU sEMG dataset, from raw .xlsx files to saved result tables and analysis outputs.

Steps executed:

  1. Load raw .xlsx files, with one file per subject
  2. Perform signal-quality screening using the DC offset ratio and standard-deviation contrast
  3. Apply preprocessing and extract nine time-domain features
  4. Run within-subject evaluation with LDA, Random Forest, XGBoost, MLP, 1D-CNN, and TCN
  5. Run the 3×3 architecture-by-threshold sensitivity analysis
  6. Run the main LOSOCV evaluation with the MLP baseline, MC Dropout, Deep Ensembles, EDL, 1D-CNN, and TCN
  7. Perform Wilcoxon signed-rank testing with Holm correction, bootstrap 95% confidence intervals, and absolute rank-biserial effect sizes
  8. Save the per-fold, per-subject, per-window, calibration, uncertainty, and ablation result tables
  9. Run NinaPro external validation conditionally when the required data are present

Configuration at the top of the script:

DATA_DIR    = '/content/'                              # folder containing .xlsx files
DRIVE_DIR   = '/content/drive/MyDrive/EMG_Revision/'  # Google Drive checkpoint path
NINAPRO_DIR = '/content/drive/MyDrive/NinaPro_DB2/'   # NinaPro data, optional

Results are checkpointed to Google Drive after each major stage, so completed analyses are retained if a Colab session disconnects.


ninapro_validation_v2.py — NinaPro DB2 External Validation

A standalone external-validation script that can be run in the same Colab session as the main pipeline or independently.

What it does:

  • Loads NinaPro DB2 Exercise B .mat files (S1_E1_A1.mat through S40_E1_A1.mat)
  • Handles the nested DB2_s{n}/DB2_s{n}/S{n}_E1_A1.mat directory structure automatically
  • Decimates the recordings from 2000 Hz to 1000 Hz
  • Applies the same preprocessing used for the YTU dataset: demeaning and 20–150 Hz bandpass filtering
  • Extracts the same nine time-domain features using 200 ms windows with 50% overlap
  • Subsamples the rest class per subject to match the mean active-class window count
  • Runs full 40-fold LOSOCV with MC Dropout
  • Reports accuracy, macro F1, ECE, the uncertainty–accuracy correlation, and selective-prediction performance across coverage levels
  • Saves the per-window, per-subject, and summary CSV files used by the revision figure-generation script

Gesture mapping for Exercise B:

NinaPro label Movement Study class
0 Rest 0 — Rest
6 Fingers flexed in fist 1 — Fist
11 Wrist flexion 2 — Wrist Flexion
12 Wrist extension 3 — Wrist Extension
5 Abduction of all fingers 4 — Hand Stretching

Publication Figure Generation — Revision

The standalone revision script regenerates six manuscript figures and one additional ablation heatmap from saved CSV files. It does not retrain any model, so final figure styling can be revised without repeating the computationally expensive experiments.

The script expects the following files in DRIVE_DIR:

within_subject_results.csv
losocv_baseline_results.csv
uq_summary.csv
uq_per_window.csv
uq_per_subject.csv
ablation_results.csv
ninapro_per_window.csv
ninapro_results.csv
ninapro_per_subject.csv

Figures generated:

  1. Within-subject versus LOSOCV accuracy across six classifiers
  2. LOSOCV method comparison and Expected Calibration Error
  3. Selective-prediction accuracy–coverage curves, including the MLP no-UQ baseline (0.511)
  4. Reliability diagrams for MC Dropout, Deep Ensembles, and EDL
  5. Per-subject uncertainty versus LOSOCV accuracy
  6. YTU–NinaPro cross-dataset selective-prediction comparison and NinaPro uncertainty scatter
  7. Architecture and feature-threshold sensitivity heatmap

Output formats:

  • PNG at 600 dpi
  • PDF
  • SVG

Figures are saved to:

/content/figures/
/content/drive/MyDrive/EMG_Revision/figures_revision/

The script uses Liberation Sans as an Arial-compatible font, applies consistent typography and panel formatting, and exports all figures with publication-ready bounding boxes.


Dataset

YTU sEMG Dataset

  • 113 healthy subjects
  • BIOPAC MP36 acquisition at 10 kHz
  • FCR channel used for the single-channel experiments
  • Five movements: Hand Free (rest), Fist, Wrist Flexion, Wrist Extension, and Hand Stretching
  • After quality screening, 83 subjects were retained in the GOOD and REVIEW tiers
  • Data are available upon reasonable request to the corresponding author

NinaPro DB2

  • 40 intact subjects
  • 12 Delsys Trigno electrodes sampled at 2 kHz
  • Exercise B, containing 17 finger and wrist movements
  • Channel index 7 used as a single circumferential forearm channel
  • Freely available at ninapro.hevs.ch
  • Citation: Atzori et al., Scientific Data, 2014

Requirements

Python >= 3.10
torch >= 2.0
numpy
pandas
scipy
scikit-learn
xgboost
matplotlib
openpyxl

Install the Python dependencies with:

pip install torch numpy pandas scipy scikit-learn xgboost matplotlib openpyxl

The scripts are designed for Google Colab with GPU acceleration and have been tested on NVIDIA T4 and A100 GPUs. Before running them, ensure that the configured data and Google Drive paths are accessible in the Colab session.


Reproducibility

All random seeds are fixed using seed=42 throughout the experimental pipelines. Results may vary by approximately ±0.001–0.003 in accuracy because of GPU non-determinism across hardware and software environments.

Expected runtimes on an NVIDIA A100:

  • Main pipeline v5: approximately 62 minutes
  • NinaPro validation v2: approximately 15 minutes

Expected runtimes on an NVIDIA T4:

  • Main pipeline v5: approximately 168 minutes
  • NinaPro validation v2: approximately 60 minutes

Key results to verify:

Metric Expected value
Random Forest WS accuracy 0.733 ± 0.133
MLP WS accuracy 0.710 ± 0.111
MC Dropout LOSOCV accuracy 0.553 ± 0.104
MC Dropout at 50% coverage 0.730
Deep Ensemble ECE 0.132–0.133
NinaPro LOSOCV accuracy, balanced 0.360 ± 0.058
NinaPro r(uncertainty, accuracy) −0.477

Citation

If you use this code or the YTU sEMG dataset, please cite:

@article{aydogan2026emguq,
  title   = {Uncertainty-Aware Single-Channel Surface EMG Classification
             for Low-Resource Hand Gesture Recognition:
             A Subject-Independent Evaluation},
  author  = {Aydoğan, Yiğit and Cantürk, İsmail},
  journal = {Medical {\&} Biological Engineering {\&} Computing},
  year    = {2026},
  note    = {Under review}
}

License

MIT License. See LICENSE for details.


Contact

Yiğit Aydoğan — corresponding author
Department of Computer Science, Aberystwyth University
yia@aber.ac.uk

About

Uncertainty-aware single-channel sEMG hand gesture classification with MC Dropout selective prediction — LOSOCV benchmark on YTU dataset and NinaPro DB2 external validation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages