
Training a sound-recognition network took just 0.9 seconds on Espressif’s ESP32-S3, a small chip for controlling electronic devices, and a larger signal-classifying network trained on the same chip in 18 seconds. That opens up a way for you to teach a device your own sounds and keep adding examples without restarting its learning. The sound demonstration distinguishes table taps from claps, although it sometimes confuses normal claps with finger claps. Take a closer look at how sound recordings become compact training data and what makes continued learning possible on this chip, as Better Stack explains.
ESP32-S3: Training a Neural Network on the Chip
TL;DR Key Takeaways :
- The ESP32-S3 trains a neural network locally from random weights to classify four signal types.
- After training, the network reaches 84.8% accuracy on previously unseen examples, matching the laptop’s result.
- The implementation makes 20,488 decisions per second, about five times faster than McCartney’s implementation on the same chip.
- Using both ESP32-S3 cores reduces the 80-step training run from 35.1 seconds to 18 seconds.
- A separate sound-recognition network trained on 30 examples in 0.9 seconds, without a computer, cloud service or GPU.
Espressif’s ESP32-S3 is a low-power microcontroller with two processor cores and a floating-point unit. In this project, it starts a neural network with random weights and trains it locally, without a laptop or cloud server in the loop.
The project uses an ESP32-S3 development board with 8 MB of PSRAM, a 1.28-inch display, an INMP441 microphone and a button, connected on a breadboard. Its code is published on GitHub.
The project builds on Bill McCartney’s work classifying sensor readings with a small neural network. McCartney trained his network on a laptop, sent the finished weights to microcontrollers and reported results for 16 microcontrollers in his blog post “Neural nets on chips that ‘can’t do’ neural nets”; a PIC16 made 2.3 decisions per second.
A Small Network Learns Four Signal Types
Given 32 sensor readings, the network produces four scores: one each for a sine wave, square wave, chirp and noise. Between the input and output are layers of 32, 16 and eight neurons. The network stores what it learns in 1,756 weights, occupying about 7 KB.
On the ESP32-S3, the project’s implementation made 20,488 decisions per second at 6.9 cycles per multiply-add, compared with McCartney’s figure of 36 cycles per multiply-add on the same chip. It was about five times faster, although neither implementation used SIMD instructions. Possible reasons include compiler optimization and keeping the weights in internal memory.
When the board starts, it generates 4,096 training examples. A Python version of the generator produces identical data, allowing the chip and laptop to learn from the same examples and be compared on the same test data.
The board’s display lets you track predictions for each signal type as training proceeds. With random starting weights, the network gets about a quarter of examples right. After training, it reaches 84.8% accuracy on previously unseen examples, matching the laptop’s result.
Expand your understanding of ESP32-S3 microcontroller with additional resources from our extensive library of articles.
- The $4 ESP32 S3 Super Mini Packs a 240 MHz Dual-Core Chip
- $4 ESP32-S3 Super Mini Packs a 0.96-Inch IPS TFT Screen
- ESP32-S3 Super Mini Brings 240 MHz Dual-Core Power For $4
- ESP32-S3 Super Mini Costs $5 and Packs Wi-Fi and Bluetooth
Training Adds Memory and Calculation Demands
For each example, the ESP32-S3 runs the network, checks its error and works backward through the layers to calculate how the weights should change. After it processes all examples, the Adam optimizer applies the changes. The project repeats that process for 80 training steps.
The work totals about 1.32 billion multiply-and-add operations on the chip running at 240 MHz. Memory is the more important limit for this network: besides the weights, training needs about 28 KB for gradients and Adam’s two running averages, plus 128 KB for the examples.
With 512 KB of internal RAM on the ESP32-S3, the training data and working values were expected to fit. The training engine is about 250 lines of plain C and uses no TensorFlow Lite or other vendor library. You can also compile it on a laptop for checks before flashing it to the board.
Two Cores Cut Training to 18 Seconds
The second core almost halves training time. The work is divided between the cores, which then add their gradients together before each weight update. Measured times for the same 80-step training run were:
- 35.1 seconds on one ESP32-S3 core.
- 18 seconds on both ESP32-S3 cores, a 1.95-times speedup.
- About 0.08 seconds using NumPy on a laptop.
At about 220 times faster, the laptop was quicker, but Better Stack considers the chip’s training time useful for a small device such as a machine sensor. Such a sensor could collect examples while running and retrain locally in less than half a minute, without being connected to a computer.
Recognize Sounds With a Microphone
A second demonstration uses the microphone to recognize sounds, starting with a separate network whose weights are random. The microphone and other components connect on the breadboard with DuPont cables.
The board detects sounds louder than the background and captures half-second recordings. Rather than feed raw audio to the network, which would be too much data for this demonstration, it converts each recording into a picture of pitch over time, represented by 161 numbers.
This front-end signal processing is particularly important for tiny networks, which rely heavily on a compact representation of the input. As the board captures each sound example, the screen displays its sound picture.
For the three classes, normal claps, finger claps and taps on a wooden table, the board records ten examples each. The original recordings remain unchanged during training; copies used for training are shifted in time and given added noise. This augmentation helps the network recognize sounds it has not encountered before.
Training the 30 examples for 40 rounds took 0.9 seconds on the board, without a computer, cloud service or GPU. Better Stack suggests subsecond training can be practical for small, specific decisions on a device.
In listening mode, the screen shows classifications and their confidence. Sounds were usually identified correctly with high confidence, and table taps were distinguished from claps very confidently, although normal and finger claps were sometimes confused.
The network can continue learning from its existing state rather than starting over. More examples and training epochs could improve accuracy, while local learning could personalize recognition to an owner’s sounds or a machine’s normal sound.
We think the speed matters less than where the learning happens. A chip that trains on the sounds it actually hears can adapt to one machine or one home in a way a factory-trained model cannot. The sound demonstration’s ability to keep learning from its existing state is important here: further examples can build on what it already knows. That makes local training more than a question of how quickly a fixed set of examples can be processed.
Your laptop can serve as a testing companion rather than a permanent part of a device’s learning setup. For anyone interested in teaching a small device to recognize sounds locally, the ESP32-S3 on-chip training project is well worth building.
Media Credit: Better Stack
Disclosure: Some of our articles include affiliate links. If you buy something through one of these links, Geeky Gadgets may earn an affiliate commission. Learn about our Disclosure Policy.