Skip to content
PetalEdgeDocs

Learning Blocks

Classification (Dense)

A small, fully connected neural network that picks a label for each window of motion data.

Try it in Studio
On this page

What is this learning block?

Classification is the default learning block for Motion projects. It is a small neural network made of dense (fully connected) layers. In Studio it appears as Classification in the Add a learning block list.

What does it do?

It takes the features of one window (for example the numbers from Spectral Analysis) and gives a score for every label, such as idle 0.05, wave 0.90, shake 0.05. The label with the highest score is the prediction.

How does it learn?

  1. The network starts with random weights.
  2. It makes a prediction for a batch of training windows.
  3. It measures how wrong the predictions were. This is the loss.
  4. It adjusts its weights a little to reduce the loss (PetalEdge uses the Adam optimizer).
  5. It repeats this for every batch. One full pass over the training data is one training cycle (epoch).

After every cycle, the model is checked on validation windows it has not trained on. Validation windows come from different recordings than training windows, so the score is honest. If the validation accuracy stops improving for 20 cycles, training stops early and the best version is kept.

What model architecture does it use?

  1. 1InputFeatures of one window
  2. 2Dense 128+ batch normalisation + dropout 0.3
  3. 3Dense 64+ batch normalisation + dropout 0.3
  4. 4OutputOne score per label (softmax)
Default Classification network
  • Dense layer: every input is connected to every neuron in the layer.
  • Batch normalisation: keeps the numbers flowing through the network in a steady range, which makes training more stable.
  • Dropout 0.3: during training, randomly switches off 30 % of the neurons, so the model can't just memorise the training data.
  • Softmax: turns the outputs into scores that add up to 1.

You can change the layers in the neural network editor on the training page.

What settings can I configure?

SettingDefaultWhat it does
Training cycles60How many passes over the training data. More cycles can learn more, but may overfit.
Learning rate0.001How big each weight adjustment is. Lower is slower but steadier.
Batch size32How many windows the model looks at before each adjustment.
Validation split0.2Share of the training data kept aside to check the model during training.
ProcessorCPUWhere training runs. Choose GPU only if your PetalEdge server offers it; otherwise the job is not started.

What problems can it solve?

Any Motion problem where each window belongs to one label:

  • gestures (wave, circle, swipe),
  • activities (walking, running, idle),
  • machine states (normal, vibrating, off).

To predict a number instead of a label (for example a speed), use the Regression learning block.

Simple example

You have three labels (idle, wave, shake), a 1000 ms window and the Spectral Analysis block. Keep the defaults and select Start training. After training, the evaluation shows that, for example, 9 of 10 wave windows were predicted as wave. When you shake the device during Live classification, shake gets the highest score.

How do I understand the training results?

  • Accuracy (per window): the share of windows that got the right label.
  • Accuracy (per recording): each whole recording gets the label most of its windows voted for. This is usually higher than the per-window accuracy.
  • Confusion matrix: a table of real labels against predicted labels. Numbers off the diagonal show which labels get mixed up.
  • Loss and accuracy graphs: training and validation should improve together. If training keeps improving while validation gets worse, the model is overfitting: add more data or use fewer training cycles.