End-to-end projects
Recognise gestures with motion sensors
Build a model that tells idle, wave and shake apart, from recording the data to downloading a package.
Try it in StudioOn this page
What you will build
A Motion model that recognises three gestures made with a sensor board in your hand:
| Label | Movement |
|---|---|
| idle | Hold the board still, or move it slowly |
| wave | Wave slowly from side to side, about once per second |
| shake | Shake quickly, several times per second |
These three differ mostly in rhythm, so the tutorial uses the Spectral Analysis block and the Classification learning block.
What you need
- A PetalEdge account.
- A way to record 3-axis accelerometer data:
- a Linux device connected to PetalEdge (see Recording from a device), or
- an Arduino UNO Q or Raspberry Pi USB sensor board and Chrome or Edge, or
- CSV files you recorded with another tool (see Uploading motion data).
- About 30 minutes.
1. Create the project
- In Studio, choose Create new project.
- Name it Gesture tutorial, choose Motion: Gesture Recognition and the Sensor device input.
- Select Create Project.
2. Record the data
Record 15 to 20 recordings per label, each about 3 to 5 seconds long.
- With a connected device: on Data acquisition, use Collect from device with Length (ms) 5000 and Frequency (Hz) 100.
- With a USB board: on Data labeling, select Connect Device, create the labels
idle,waveandshakein Gesture labels, then use Record a sample. - With CSV files: name them
idle.01.csv,wave.01.csv, … and upload them with Infer from filename and Automatically split between training and testing.
Record about 80 % into Training and 20 % into Testing. Vary how you hold the board a little between recordings.
3. Check the data
Open Data labeling. Check that every label has recordings in both Training and Testing, open a few recordings in the signal viewer, and delete any that went wrong.
4. Design the impulse
Open Create impulse and set:
| Setting | Value |
|---|---|
| Input axes | The three accelerometer axes (e.g. accX, accY, accZ) |
| Window (ms) | 1000 |
| Increase (ms) | 500 |
- Add a processing block → Spectral Analysis.
- Add a learning block → Classification.
- Select Save Impulse.
A 1-second window is long enough to hold at least one full wave.
5. Generate features
- Open Spectral Analysis in the left menu.
- Keep the default parameters and select Save parameters.
- On the Generate features tab, select Generate features.
- In the feature explorer, idle, wave and shake should form three groups.
6. Train
- Open Classification in the left menu.
- Keep the defaults: Training cycles 60, Learning rate 0.001.
- Select Start training and wait for Training output to finish.
7. Evaluate and test
- Open Evaluation. Look at Per window and Per recording accuracy and the confusion matrix.
- Open Model testing and select Classify all.
- If you have a connected device, open Live classification, select Start Session, and try each gesture. Watch the Prediction timeline.
If wave and shake get mixed up, record more examples of both, with a clearer difference in speed, and retrain.
8. Deploy
- Open Deployment.
- Choose Generic tf lite (or Raspberry Pi) as the target.
- Choose a Precision. Compare the scores of Unoptimized (float32) and Quantized (int8).
- Select Build Deployment Package, then Download Latest Build.
What you learned
- How to record and label motion data.
- How windows turn recordings into training examples.
- Why Spectral Analysis suits rhythmic gestures.
- How to read per-window and per-recording results.
- How to build a deployment package.