← Projects

Evaluating TinyML Performance on ESP32 and ESP32-CAM

2025 · TensorFlow Lite Micro, Edge Impulse · Course project

An ESP32-CAM board on a desk

In this article I will guide you through my recent project where I explored the use of TinyML on edge devices.

The use of machine learning is common in high-performance computing, but running these models on small, low-power devices like the ESP32 is a challenge. In this project, I aimed to evaluate the performance of TinyML to understand its feasibility, limitations, and optimization techniques. Let’s get started.

Things you will need
  • ESP32 Development Board (For general ML tasks)
  • ESP32-CAM (For vision applications)
  • ICM20948 Sensor (9-axis IMU for motion tracking)
  • INA219 Sensor (To measure power consumption)
  • Software: Arduino IDE, TensorFlow Lite for Microcontrollers, and Edge Impulse Studio.
A microcontroller board and a small sensor breakout wired together on green perfboard, held in a hand
One of the test boards, wired on perfboard.
Now follow the point-by-point breakdown of the project below:

1. The Goal and Models I wanted to test various complexities of Machine Learning models. I selected four specific types for this experiment:

  • Linear Regression: To predict city temperatures.
  • K-Nearest Neighbors (KNN): To classify Titanic passenger survival.
  • Object Detection (CNN): To detect fruits (Apples) using the ESP32-CAM.
  • Motion Tracking: To detect hand gestures using the IMU sensor.

2. The Workflow: For the implementation, I followed a systematic process. Since the ESP32 cannot handle heavy training, I trained the models locally on Google Colab or using Edge Impulse.
After training, the TensorFlow Lite models were converted into C arrays (header files) and embedded directly into the ESP32’s flash memory.

3. Performance Results: Here is what happened when I actually ran them on the hardware:

  • Linear Regression: This worked great! It achieved 72.5% accuracy with very low latency (3.2ms) and minimal memory usage.
  • KNN: This was a failure. It only reached 58.3% accuracy and struggled because of the ESP32’s RAM limitations. It turns out some models are just too heavy for these chips.
  • Motion Tracking: This achieved 87.2% accuracy after optimization and wasn’t too demanding on the processor.

4. Optimizing Object Detection (The Tricky Part)

Running image recognition on an ESP32-CAM is tough. The baseline accuracy was 70.1% with high latency. To fix this, I used Quantization (converting FP32 to INT8) and Pruning. Using MobileNetV2 as the base architecture was crucial here.

An ESP32-CAM board connected by USB on a desk
The ESP32-CAM used for the vision experiments.
  • Reduced the image resolution to grayscale 96×96.
  • Applied 40% pruning with INT8 quantization.

Result: The accuracy bumped up to 74.3%, latency dropped to 9ms, and the model size shrank by over 34%

Line chart of model accuracy against numerical precision, from INT8 to FP32, with INT8 marked as the optimal trade-off
Accuracy against numerical precision. INT8 was the best trade-off.
Line chart of INT8 model accuracy against pruning level from 0 to 80 percent, peaking at 40 percent
Accuracy against pruning level for the INT8 model. 40% pruning gave the best balance.

Conclusion: This project demonstrated that TinyML is definitely capable of delivering practical performance on resource-constrained devices. While simple models work out of the box, complex vision models require careful optimization like quantization and pruning to balance accuracy and efficiency.