GestureFlow is a lightweight, end-to-end Machine Learning Hand Gesture Recognition System built using PyTorch, OpenCV, and MediaPipe. Developed on the 20,000-image LeapGestRecog infrared gesture dataset, GestureFlow demonstrates the complete ML lifecycleโfrom scientific dataset auditing and subject-isolated splitting to CNN architecture design, empirical evaluation, and live real-time desktop webcam demonstration.
Hand gesture recognition enables natural human-computer interaction (HCI) without physical contact. However, deploying real-time vision models on desktop environments introduces key engineering challenges:
- Subject Data Leakage: Standard random train/test splits cause severe over-optimistic validation metrics due to background and subject feature memorization.
- Computational Footprint: Standard heavy vision networks (e.g., ResNet-50) require gigabytes of memory and dedicated GPU hardware, causing high latency on standard desktop CPUs.
- Inference Latency & Jitter: Raw per-frame classification leads to flickering predictions when hand ROI bounding boxes change slightly across camera frames.
GestureFlow solves these challenges by combining a custom 422,506-parameter PyTorch GestureCNN, strict subject-isolated dataset partitioning, MediaPipe hand ROI localization, and temporal majority-voting prediction stabilization.
- ๐ฌ Scientific Dataset Audit: SHA-256 duplicate image scanning across 20,000 images, computing exact mean/std normalization values (
mean=0.2435,std=0.2330). - ๐ก๏ธ Strict Subject-Aware Splitting: Zero subject overlap across splits (
$70%$ train /$15%$ val /$15%$ test) ensuring authentic generalization measurement. - โก Lightweight GestureCNN Architecture: 4 convolutional blocks + Global Average Pooling (GAP) achieving 422,506 parameters and a 1.625 MB FP32 footprint.
- ๐ฏ 100.00% Offline Test Accuracy: Evaluated on held-out Subject
09with 1.0000 Macro F1 and 3.98 ms per-image CPU inference latency. - ๐ท Real-Time OpenCV Webcam HUD: Live desktop webcam demonstration featuring hand ROI extraction, multi-mode image processing (Gray / HistEq / CLAHE), and real-time visual telemetry overlay.
- ๐ ๏ธ Developer Debug Window: Live side-by-side inspection of raw hand ROI, normalized 2D tensor heatmap, and Top-3 class probability confidence bars.
- ๐ Prediction Stabilizer: Multi-stage temporal majority voting with confidence gating (
$\ge 70%$ ) eliminating real-time prediction flicker.
GestureFlow recognizes 10 distinct hand gesture categories from the LeapGestRecog dataset:
| Index | Class Name | Description |
|---|---|---|
0 |
01_palm |
Open palm facing forward |
1 |
02_l |
L-shape gesture (index finger and thumb extended) |
2 |
03_fist |
Closed stationary fist |
3 |
04_fist_moved |
Closed fist in motion |
4 |
05_thumb |
Thumbs-up gesture |
5 |
06_index |
Index finger pointing |
6 |
07_ok |
OK sign (circle formed by index and thumb) |
7 |
08_palm_moved |
Open palm in motion |
8 |
09_c |
C-shape hand curve |
9 |
10_down |
Palm pointing downwards |
GestureFlow is trained and evaluated on the LeapGestRecog dataset:
-
Total Images: 20,000 grayscale infrared PNG images (
$640 \times 240$ resolution). -
Subjects: 10 human subjects (
00through09), 2,000 images per subject. - Classes: 10 gesture classes, 200 images per subject-class pair.
To prevent subject data leakage, images originating from the same human subject are strictly isolated:
Dataset (20,000 Images / 10 Subjects)
โโโ Training Split : Subjects 00, 01, 02, 03, 04, 05, 06 (14,000 images / 70.0%)
โโโ Validation Split : Subjects 07, 08 (4,000 images / 20.0%)
โโโ Test Split : Subject 09 (2,000 images / 10.0%)
Why Subject Isolation Matters: Random image splitting places images of the same hand/subject in both train and test sets, allowing models to memorize skin tone, background clutter, or subject height. Subject-aware splitting guarantees that test evaluation reflects true unseen subject generalization.
Dataset โ Preprocessing โ GestureCNN โ Evaluation โ Real-Time Webcam Demo
[Webcam Stream] โ [MediaPipe Hand Detector] โ [Hand ROI Crop & Padding] โ [128x128 Grayscale Normalization] โ [PyTorch GestureCNN] โ [Prediction Stabilizer] โ [OpenCV Telemetry HUD]
GestureCNN features 4 Conv blocks, Batch Normalization, ReLU activations, 2x2 Max Pooling, Global Average Pooling (GAP), and a 2-layer fully-connected head:
Input: (B, 1, 128, 128)
โโโ ConvBlock 1: Conv2d(1 -> 32, 3x3) -> BatchNorm2d -> ReLU -> MaxPool2d(2x2) -> (B, 32, 64, 64)
โโโ ConvBlock 2: Conv2d(32 -> 64, 3x3) -> BatchNorm2d -> ReLU -> MaxPool2d(2x2) -> (B, 64, 32, 32)
โโโ ConvBlock 3: Conv2d(64 -> 128, 3x3) -> BatchNorm2d -> ReLU -> MaxPool2d(2x2) -> (B, 128, 16, 16)
โโโ ConvBlock 4: Conv2d(128 -> 256, 3x3)-> BatchNorm2d -> ReLU -> MaxPool2d(2x2) -> (B, 256, 8, 8)
โโโ Global Average Pooling: AdaptiveAvgPool2d((1, 1)) -> (B, 256, 1, 1)
โโโ Flatten -> (B, 256)
โโโ Dense FC 1: Linear(256 -> 128) -> ReLU -> Dropout(p=0.4) -> (B, 128)
โโโ Dense FC 2: Linear(128 -> 10) -> (B, 10)
- Total Trainable Parameters:
422,506 - FP32 Checkpoint Size:
1.625 MB - FLOPs / MACs:
466.42 MFLOPs/233.21 MMACs
Evaluating models/checkpoints/best_model.pth on the held-out Subject 09 test set (2,000 images):
| Metric | Target Standard | Verified Result |
|---|---|---|
| Test Classification Accuracy | 100.00% | |
| Macro F1-Score | 1.0000 | |
| Macro Precision | 1.0000 | |
| Macro Recall | 1.0000 | |
| Average CPU Inference Latency |
3.98 ms ( |
|
| Model Size (FP32) | 1.625 MB | |
| Trainable Parameters | โ | 422,506 |
- Python:
3.10,3.11, or3.12 - Operating System: Windows, macOS, or Linux
git clone https://github.com/Pannaga-Hegde/GestureFlow.git
cd GestureFlow# Windows
python -m venv .venv
.venv\Scripts\activate
# macOS / Linux
python3 -m venv .venv
source .venv/bin/activatepip install --upgrade pip
pip install -r requirements.txtVerify that all 60 modular unit tests pass cleanly:
$env:PYTHONPATH="."; pytest tests/python -m src.dataset.verify_integritypython -m src.training.trainpython -m src.evaluation.evaluate# Standard Live Webcam Stream (Camera Index 0)
$env:PYTHONPATH="."; python -m src.inference.demo
# Headless / Synthetic Mock Mode (runs 50 frames without camera hardware)
$env:PYTHONPATH="."; python -m src.inference.demo --mock --frames 50
# Custom Camera Index & Preprocessing Mode
$env:PYTHONPATH="."; python -m src.inference.demo --camera 1 --mode clahe --devWhile the OpenCV webcam window is focused:
| Key | Action | Description |
|---|---|---|
Q |
Quit | Gracefully releases camera and saves session summary |
D |
Developer Mode | Toggles side-by-side ROI crop and tensor probability window |
1 |
Gray Mode | Sets preprocessing to standard grayscale |
2 |
HistEq Mode | Sets preprocessing to global histogram equalization |
3 |
CLAHE Mode | Sets preprocessing to Contrast Limited Adaptive Histogram Equalization |
P |
Pause / Resume | Pauses CNN forward pass |
F |
Toggle FPS | Toggles FPS telemetry readout |
H |
Toggle Telemetry | Toggles dark-slate HUD overlay |
C / SPACE |
Screenshot | Captures image snapshot to outputs/inference/screenshots/ |
O |
Debug Bundle | Saves frame, ROI, normalized tensor, and prediction JSON to outputs/inference/debug/ |
R |
Reset Stats | Resets session statistics and stabilizer buffer |
- IR vs RGB Domain Shift (Primary Limitation):
The
LeapGestRecogdataset consists of near-infrared (IR) sensor imagery, whereas standard webcams capture visible-light RGB imagery. Consequently, while the trained model achieves 100.00% accuracy on infrared test data, real-world RGB webcams may exhibit lower confidence due to background clutter, lighting variations, and skin-tone domain shifts. Mitigation: Hand ROI cropping via MediaPipe combined with single-channel grayscale normalization minimizes background domain variance. - Single Hand Isolation: MediaPipe detector is configured for single-hand ROI extraction. Multi-person or dual-hand interaction is not supported.
- Stationary Framing: Complex rapid hand motion introduces motion blur, which can degrade ROI localization confidence.
- ๐ท RGB Dataset Integration: Fine-tune model on real-world RGB gesture benchmarks (e.g., EgoGesture, HaVGD).
- ๐ Domain Adaptation: Implement adversarial domain adaptation (DANN) to bridge Infrared
$\to$ Visible RGB feature distributions. - โณ Temporal Sequence Modeling: Incorporate lightweight GRU or Temporal Convolutional Networks (TCN) for dynamic multi-frame gesture recognition (e.g., swipes, pinches).
- ๐ฆด Landmark-Based Models: Train lightweight GNN/MLP models directly on MediaPipe 21 3D hand keypoints for ultra-fast sub-1ms CPU inference.
This project is open-source and released under the MIT License.
Dataset Attribution: The LeapGestRecog dataset is used under research and educational fair-use terms.
- GTI (Grupo de Tratamiento de Imรกgenes): Authors of the LeapGestRecog dataset.
- MediaPipe Team: Google Open Source MediaPipe Hands framework.
- PyTorch & OpenCV Communities: Core vision and deep learning tools.




