An open API service indexing awesome lists of open source software.

https://github.com/tayo4christ/transformer-gesture

Real-time gesture recognition system using Vision Transformers, ONNX, and Gradio. Includes dataset preparation, training, evaluation, and a browser-based demo app.
https://github.com/tayo4christ/transformer-gesture

accessibility-tutorial computer-vision deep-learning gesture-recognition gradio onnx onnxruntime pytorch sign-language transformers

Last synced: about 2 months ago
JSON representation

Real-time gesture recognition system using Vision Transformers, ONNX, and Gradio. Includes dataset preparation, training, evaluation, and a browser-based demo app.

Awesome Lists containing this project

README

          

![Python](https://img.shields.io/badge/python-3.8+-blue.svg)
![PyTorch](https://img.shields.io/badge/PyTorch-2.0+-red.svg)
![ONNX](https://img.shields.io/badge/ONNX-runtime-green.svg)
![Gradio](https://img.shields.io/badge/Gradio-app-orange.svg)

# Transformer Gesture Recognition πŸŽ₯βž‘οΈπŸ€–

This project shows how to build a **Transformer-based gesture recognition system** using PyTorch, ONNX, and Gradio. You’ll train on a small dataset, export to ONNX for faster inference, and run a real-time demo app.

---

## Project Structure

```
transformer-gesture/
β”‚
β”œβ”€β”€ data/ # Put your gesture videos here
β”‚ β”œβ”€β”€ swipe_left/
β”‚ β”œβ”€β”€ swipe_right/
β”‚ └── stop/
β”‚
β”œβ”€β”€ images/ # Screenshots for tutorial & README
β”‚ β”œβ”€β”€ training-logs.png
β”‚ β”œβ”€β”€ confusion-matrix.png
β”‚ └── realtime-demo.png
β”‚
β”œβ”€β”€ labels.txt # One class name per line (matches folders in data/)
β”œβ”€β”€ dataset.py # Dataset loader
β”œβ”€β”€ train.py # Training script
β”œβ”€β”€ export_onnx.py # Export trained model to ONNX
β”œβ”€β”€ app.py # Gradio demo app (upload/record gestures)
β”œβ”€β”€ eval.py # Evaluate accuracy + confusion matrix
β”œβ”€β”€ benchmark.py # Measure inference latency
β”œβ”€β”€ requirements.txt # Dependencies
└── README.md # This file
```

---

## Setup

1. Clone this repo and create a virtual environment:
```bash
git clone
cd transformer-gesture
python -m venv .venv
source .venv/bin/activate # (Linux/Mac)
.venv\Scripts\activate # (Windows)
```

2. Install requirements:
```bash
pip install -r requirements.txt
```

---

## Prepare Data

Place your gesture videos under `data//`. For example:

```
data/
β”œβ”€β”€ swipe_left/
β”‚ β”œβ”€β”€ clip1.mp4
β”‚ └── clip2.mp4
β”œβ”€β”€ swipe_right/
└── stop/
```

Update `labels.txt` so each line matches the folder names:

```
swipe_left
swipe_right
stop
```

πŸ’‘ Tip: In the Gradio app, you can also **record clips directly from your webcam**.

---

## Train the Model

```bash
python train.py
```

This saves the best weights to `vit_temporal_best.pt`.

Here’s what the training logs look like:

![Training logs](images/training-logs.png)

---

## Export to ONNX

```bash
python export_onnx.py
```

Generates `vit_temporal.onnx` for fast inference.

---

## Run the Demo App

```bash
python app.py
```

Open the URL shown in the terminal (default: `http://127.0.0.1:7860`). You can record a short gesture and get predictions like this:

![Gradio demo output](images/realtime-demo.png)

---

## Evaluate Accuracy

```bash
python eval.py
```

Prints validation accuracy and displays a confusion matrix heatmap:

![Confusion matrix](images/confusion-matrix.png)

---

## Benchmark Latency

```bash
python benchmark.py
```

Measures average inference time per clip.

---

## Notes

- This project is intended as a **tutorial/demo**, not production code.
- For higher accuracy, expand your dataset or use a stronger video Transformer like **TimeSformer** or **VideoMAE**.
- Always consider **accessibility, fairness, and ethical use** when deploying gesture/speech models.