CyclingSafety
Classifying cycling risk events from inertial sensor data, from model experiments to an INT8-quantized model on an ESP32.

Overview
CyclingSafety turns smartphone and wearable inertial signals into a multiclass classification of cycling risk events, then explores deploying that model on a low-cost ESP32 device.
Problem and objective
Urban cyclists face potholes, sudden braking, and uneven surfaces. Detecting these events from inertial data could support safer routes and post-ride analysis, but the model has to run close to the rider, not only in the cloud.
Role and contributions
I built the data and model pipeline, ran MLP and 1D-CNN experiments with Bayesian hyperparameter search, quantized the selected model, and integrated the embedded prototype with sensors, GPS, storage, and MQTT reporting.
Solution and architecture
The pipeline moves from IMU windows to a multiclass model, then to an INT8 TensorFlow Lite model for microcontrollers. On the ESP32, the MPU-6050 provides inertial data, the NEO-6M adds GPS, microSD stores logs, and MQTT forwards detected events to ThingsBoard. Python and Folium render event maps and severity heatmaps.
Technical implementation
The 1D-CNN operates directly on time-series windows, while the MLP uses engineered features. KerasTuner searches architecture and training parameters. INT8 quantization shrinks the artifact for TensorFlow Lite Micro, and event predictions are joined with GPS coordinates to produce maps.
Engineering decisions
- On-device inference
- Running the model on the ESP32 reduces dependence on connectivity and keeps raw sensor data local, at the cost of a smaller model and a tighter compute budget.
- 1D-CNN over engineered features
- Convolutional windows learn local temporal patterns, while the MLP remains a lighter baseline for comparison.
- Quantization for deployment
- INT8 quantization makes the model fit microcontroller constraints; the trade-off is a measurable gap between conversion benchmarks and field behaviour.
Results
The project report documents an approximately 90.5% reduction in artifact size through quantization. Embedded field classification performance was lower than with smartphone-based data, which is reported here rather than smoothed over.
Limitations
The notebook documents window-level splitting with overlapping windows, so exploratory classification metrics may be affected by leakage. Those metrics should not be read as definitive generalization performance on unseen rides. Quantization results describe model conversion, not ESP32 field accuracy.
Technologies
- Python
- TensorFlow / Keras
- KerasTuner
- TensorFlow Lite Micro
- ESP32
- MPU-6050
- NEO-6M GPS
- MQTT
- ThingsBoard
- Folium