https://github.com/sankoktas/bhi360-fall-detection
Fall detection system using Bosch BHI360 sensor data with time-series labeling, feature extraction, and machine learning (LOSO CV + Gradient Boosting).
https://github.com/sankoktas/bhi360-fall-detection
accelerometer bhi360 bosch-sensors data-augmentation fall-detection feature-extraction gradient-boosting gyroscope human-activity-recognition label-studio loso-cross-validation machine-learning python scikit-learn sensor-data smote time-series
Last synced: 26 days ago
JSON representation
Fall detection system using Bosch BHI360 sensor data with time-series labeling, feature extraction, and machine learning (LOSO CV + Gradient Boosting).
- Host: GitHub
- URL: https://github.com/sankoktas/bhi360-fall-detection
- Owner: sankoktas
- Created: 2025-03-22T21:10:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-20T20:57:21.000Z (about 1 year ago)
- Last Synced: 2025-07-25T03:33:02.736Z (10 months ago)
- Topics: accelerometer, bhi360, bosch-sensors, data-augmentation, fall-detection, feature-extraction, gradient-boosting, gyroscope, human-activity-recognition, label-studio, loso-cross-validation, machine-learning, python, scikit-learn, sensor-data, smote, time-series
- Language: Jupyter Notebook
- Homepage:
- Size: 49.5 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ง Embedded Fall Detection Pipeline with Wrist-Worn IMU Data
This project implements a complete, embedded-ready pipeline for **human activity recognition and fall detection** using wrist-mounted **Bosch BHI360** sensor data. Developed as part of a master's thesis, it demonstrates the feasibility of deploying machine learning models entirely **on-device**, on ultra-low-power hardware, without the need for external computation or connectivity.
---
## ๐ Overview
Falls are a major cause of injury and hospitalization among older adults. Detecting them early using wearables can enable faster intervention, improve safety, and reduce healthcare costs. However, many machine learning solutions are too resource-hungry for deployment on microcontrollers.
This project bridges that gap by combining:
- ๐ฏ Accurate **fall detection using inertial signals**
- โ๏ธ Lightweight, efficient **decision tree models**
- ๐ง Real-time **on-device inference** using embedded firmware
- ๐ Evaluation via **Leave-One-Session-Out Cross-Validation**
- ๐ง Feature-rich yet embedded-compatible model engineering
---
## ๐งพ Data Collection Info
- ๐ฆ **Sensor:** Bosch BHI360 Shuttle Board
- ๐ง **Firmware:** `Bosch_Shuttle3_BHI360_BMM150.fw`
- ๐ **Sensor Configuration:**
- Accelerometer (Corrected, Non-Wakeup) at **200 Hz**
- Gyroscope (Corrected, Non-Wakeup) at **200 Hz**
Data was logged as JSON and then processed using this notebook for machine learning.
---
## ๐ Files & Structure
- `app.ipynb` โ Main Jupyter notebook for preprocessing, training, evaluation
- `training_data.csv` โ Final training-ready dataset with session IDs
---
## ๐ ๏ธ Label Studio Setup
Use this config when importing time series data into Label Studio:
```xml
```
---
## ๐ฆ Pipeline Components
### โ
Label Parsing & Preprocessing
- Raw IMU (accelerometer + gyroscope) data collected at **200 Hz**
- JSON logs parsed and restructured into consistent time-series frames
- Corrupted or incomplete samples removed
- Labels merged from **Label Studio** annotations using session timestamps
### ๐ Feature Extraction
- Extracted from **2-second windows** with **0.25-second hops**
- Includes:
- Time-domain features (mean, variance, skewness, kurtosis, range, percentiles)
- Frequency-domain features (FFT energy, dominant frequency index)
- Custom heuristics (impact peak, jerk magnitude, signal magnitude area, time to peak)
### โ๏ธ Data Augmentation + Balancing
- Class imbalance addressed using **SMOTE**
- Optional augmentation for rare event simulation
### ๐ค Model Training
- Two classifiers compared:
- `HistGradientBoostingClassifier` โ high-performing, but too large for embedded use
- `DecisionTreeClassifier` โ slightly lower accuracy, but fits into embedded memory
- Trained using **Leave-One-Session-Out (LOSO) cross-validation** to test generalization
### ๐ Evaluation
- Reports:
- Per-class precision, recall, F1
- Overall macro scores
- Includes:
- Confusion matrices
- Metric plots
---
## ๐ Firmware Deployment
The trained `DecisionTreeClassifier` was exported to C using [`m2cgen`](https://github.com/BayesWitnesses/m2cgen) and embedded into the BHI360 firmware.
Key integration steps:
- `model.c` and `model.h` inserted under `libs/my_classifier/`
- Wrapper function created to expose inference to SDK
- Custom virtual driver `VirtMyClassifier` written to invoke the model
- Registered under:
- `boards/Bosch_Shuttle3_BHI360_MyModel.cfg`
- `common/config.7189_di03_rtos_bhi360.cmake`
- Final firmware image:
`release/gccfw/Bosch_Shuttle3_BHI360_MyModel.fw`
Flashing can be done via **Bosch Development Desktop 2.0**.
More details about firmware deployment in the README file under the SDK folder.
---
## ๐งพ Data Collection Info
- ๐ค **Subject:** One healthy adult, 30 sessions
- ๐ **Placement:** Left wrist (taped securely)
- ๐ **Sampling:** 200 Hz (accelerometer + gyroscope)
- ๐ง **Sensor Platform:** Bosch Shuttle Board 3.0 + Application Board 3.1
- ๐ **Firmware Used for Collection:** `Bosch_Shuttle3_BHI360_BMM150.fw`
Each session includes:
- Static idle
- General arm motion
- Sit-to-stand and stand-to-sit transitions
- Simulated forward, backward, and lateral falls
---
## ๐ Reproducibility
To replicate the results:
- Record inertial data with the BHI360 at 200 Hz.
- Annotate using Label Studio and the template above.
- Run app.ipynb to preprocess, extract features, and train models.
- Use m2cgen to export the selected model to C.
- Integrate the C code into the SDK and build the firmware.
- Flash Bosch_Shuttle3_BHI360_MyModel.fw using Bosch Desktop 2.0
## ๐ฃ Acknowledgements
This project was built using Bosch Sensortec hardware and SDK, with thanks to the open-source ML community for tools like scikit-learn, m2cgen, and Label Studio.