↓ Skip to main content

ESP-TFLite-Micro workshop - Assignment 4: Deploy and test on-device inference

·4 mins·
Table of Contents
WS004EN - This article is part of a series.
Part 9: This Article

Recap from Assignment 3
#

In the previous assignment, you converted simple_1dcnn_model.h5 to TensorFlow Lite and verified its interface:

Input:  float32 [1, 200, 3]
Output: float32 [1, 4]

You then converted model.tflite into model.cpp and replaced the model source in the gesture recognition application. The example’s existing model.h already declares the required symbols:

1gesture_recognition/
2└── main/
3    ├── model.cpp
4    └── include/
5        └── model.h

The model now embedded in the ESP-IDF project recognizes the three original classes plus the movement collected in Assignment 1. The remaining task is to synchronize the application labels, build the firmware, and test inference on the ESP-SensairShuttle.

What you will do
#

In this assignment, you will:

  1. Add the new gesture name to the application label table.
  2. Build and flash the updated firmware.
  3. Test all four classes and record the results.

Assignment steps
#

Step 1: Update the class labels
#

Open main/app_model.cpp and find kLabels. Replace the complete array so its order matches the labels used during training:

1static const char *kLabels[] = {
2    "Counterclockwise circle",
3    "V",
4    "Unknown",
5    "YOUR_GESTURE",
6};

Replace YOUR_GESTURE with the name of the movement collected in Assignment 1.

The array order must match the training labels exactly: circle is 0, V is 1, unknown is 2, and the new gesture is 3. A different order displays the wrong name even when the model predicts the correct output index.

No other source changes are required for the fourth class:

  • app_model.cpp reads the class count from output->dims->data[1].
  • app_model_pipeline.cpp handles class IDs without assuming a fixed count.
  • The BMI270 configuration and 200 × 3 input pipeline remain unchanged.
  • model.cpp was already replaced in Assignment 3; the existing model.h remains unchanged.

Step 2: Build the application
#

  1. Select File → Open Folder and open the gesture_recognition project directory, not its training subdirectory.
  2. Run ESP-IDF: Build Your Project from the Command Palette.
  3. Follow the build output in VS Code.

From the gesture_recognition project directory, build with the ESP-IDF v6.1 environment activated:

idf.py build

The first build may take longer while the Component Manager downloads dependencies.

If compilation reports an undefined model symbol, confirm:

  • main/model.cpp defines model_tflite and model_tflite_len.
  • main/include/model.h declares the same names and types.
  • main/CMakeLists.txt includes the main source directory.

Step 3: Flash and monitor
#

  1. Run ESP-IDF: Select Port to Use from the Command Palette and select the ESP-SensairShuttle.
  2. Run ESP-IDF: Build, Flash and Start a Monitor on Your Device.
  3. Select UART if prompted.
  4. Use the trash-can icon in the VS Code Terminal panel to stop the monitor.

Replace <PORT> with the serial port used earlier:

idf.py -p <PORT> flash monitor

Press Ctrl+] to exit the monitor.

Move the board using one of the trained gestures. Expected output resembles:

I (...) Model Pipeline: Motion detected: Counterclockwise circle (confidence: 98.4%)
I (...) Model Pipeline: Motion detected: YOUR_GESTURE (confidence: 94.7%)
I (...) Model Pipeline: Motion detected: Unknown (confidence: 91.2%)

Class names, confidence values, and timestamps depend on your model and movement.

Step 4: Validate physical gestures
#

Use the same grip and board orientation used during data collection. Perform at least 10 trials per class and record every result, including incorrect classifications and rejected movements.

GestureTrialsCorrectIncorrectRejected
Counterclockwise circle10
V gesture10
Unknown movements10
New gesture10

For this workshop, aim for at least 7 correct detections out of 10 for each intentional gesture. This is a workshop checkpoint, not a production-quality acceptance threshold.

If the new gesture performs poorly:

  1. Confirm that kLabels uses the correct class order.
  2. Repeat the movement with the training grip, orientation, speed, and amplitude.
  3. Review the confusion matrix from Assignment 2.
  4. Collect more varied samples and retrain.
  5. Adjust the trigger or confidence threshold only after checking the dataset and model.

Acceptance criteria
#

  • The project builds successfully for ESP32-C5.
  • Tensor allocation completes without errors.
  • BMI270 data fills a float32 input tensor with shape (1, 200, 3).
  • Inference returns four class scores.
  • kLabels contains four names in training-label order.
  • Serial output reports class names and confidence values.
  • Physical tests include all four classes with at least 10 trials each.

Going further
#

  • Collect data from more participants and orientations.
  • Compare float32 and fully quantized models.
  • Measure tensor arena usage and inference latency.
  • Tune trigger and confidence thresholds using recorded results.
  • Test the model with gestures performed by people not represented in the training dataset.

Conclusion
#

You collected a new gesture, trained and converted a four-class model, embedded it in an ESP-IDF application, and ran inference locally on the ESP32-C5.

Back to workshop home

WS004EN - This article is part of a series.
Part 9: This Article

Related