How shawnhymel/tinyml-example-anomaly-detection works
This repository is an end-to-end TinyML anomaly-detection example for electric motors: ESP32 accelerometer samples are collected, analyzed for useful features, used to train either a Mahalanobis-distance model or an autoencoder, and deployed to a server or ESP32. The README documents the overall workflow and alternatives; source excerpts show HTTP collection and server-side inference. Training notebooks, device sketches, and most conversion/deployment internals were not sampled, so their connections are limited to documented workflow links.
Main entry points: datasets CSV datasets · anomaly-detection-training-md-deploy.py MD deployment conversion · anomaly-detection-tflite-conversion.ipynb TFLite conversion · md_model-moving.h MD model parameters
Components 18
Data acquisition
- Capture firmware
data_collection/esp32_accel_post/esp32_accel_post.ino - Sample collector
data_collection/http_accel_server.py - CSV datasets
datasets
Analysis and training
- Feature analysis
data_collection/anomaly-detection-feature-analysis.ipynb - Mahalanobis training
mahalanobis_distance/anomaly-detection-training-mahalanobis-distance.ipynb - Autoencoder training
autoencoder/anomaly-detection-training-autoencoder.ipynb - MD deployment conversion
mahalanobis_distance/anomaly-detection-training-md-deploy.py - TFLite conversion
autoencoder/anomaly-detection-tflite-conversion.ipynb - C array writer
utils/c_writer.py
Inference
- MD inference server
mahalanobis_distance/http_server_anomaly_detection_md.py - Autoencoder inference server
autoencoder/http_server_anomaly_detection_tflite.py
Embedded deployment
- MD ESP32 deployment
mahalanobis_distance/esp32_deploy_md - MD model parameters
mahalanobis_distance/esp32_deploy_md/md_model-moving.h - Autoencoder ESP32 deployment
autoencoder/esp32_deploy_tflite/esp32_deploy_tflite.ino - TFLite model array
autoencoder/esp32_deploy_tflite/fan_low_model.h - MD ESP32 test
mahalanobis_distance/esp32_test_md - Autoencoder ESP32 test
autoencoder/esp32_test_tflite
Other components
- ESP32 accelerometer
Connections 20
- ESP32 accelerometer → Capture firmware: measures motion
README.md - Capture firmware → Sample collector: posts samples
README.md - Sample collector → CSV datasets: writes CSV
data_collection/http_accel_server.py - CSV datasets → Feature analysis: analyzed as
README.md - CSV datasets → Mahalanobis training: trains from
README.md - CSV datasets → Autoencoder training: trains from
README.md - Mahalanobis training → MD deployment conversion: exports model
README.md - Autoencoder training → TFLite conversion: converts model
README.md - MD deployment conversion → C array writer: uses writer
- TFLite conversion → C array writer: uses writer
- ESP32 accelerometer → MD inference server: sends samples
- ESP32 accelerometer → Autoencoder inference server: sends samples
- MD deployment conversion → MD inference server: provides model
- TFLite conversion → Autoencoder inference server: provides model
- MD deployment conversion → MD model parameters: exports parameters
- TFLite conversion → TFLite model array: exports model
- MD model parameters → MD ESP32 deployment: compiled into
- TFLite model array → Autoencoder ESP32 deployment: compiled into
- MD model parameters → MD ESP32 test: used by test
- TFLite model array → Autoencoder ESP32 test: used by test