An open API service indexing awesome lists of open source software.

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).

Awesome Lists containing this project

README

          


Motion Classification Pipeline Banner

# ๐Ÿง  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.