Skip to content

tree-based-har/TreeBasedTinyHAR

Repository files navigation

Tree-Based HAR TinyML Codebase

This repository contains the source code for the dataset processing, feature extraction, and training of tree-based models (Decision Tree and Random Forest) optimized for highly resource-constrained microcontrollers (i.e., Arduino UNO, ESP32) from the study titled Decision tree-based real-time personalized Human Activity Recognition and fall detection utilizing cost effective highly resource-constrained microcontrollers. The study is also publicly available on SSRN as a preprint.

Structure of the Repository

├── CITATION.cff  # For academic citation
├── config.py  # Hyperparameters and other configuration values
├── data_pipeline
│   └── preprocessing.py  # Helper script to load and process HAPT and UMAFall datasets
├── models
│   └── tree_models.py  # Definitions for Decision Tree and Random Forest models with discretization
├── README.md
├── requirements.txt  # Python dependencies
├── run_deployment_prep.py  # Convert trained models to C++ header files using micromlgen
├── run_preprocessing.py  # Run the data pipeline to extract features
└── run_training.py  # Train and evaluate the models
  • Data Pipeline: Preprocessing scripts for the UCI HAPT and UMAFall datasets, implementing a sliding window approach and statistical feature extraction tailored for microcontrollers.
  • Optimized Tree Models: Python classes wrapping scikit-learn's Decision Tree and Random Forest algorithms with an 8-bit integer quantization proxy (discretization).
  • Deployment Prep: Converts the trained and optimized models into integer-only C++ header files utilizing the micromlgen library.

Usages

1. Environment Setup

Install the necessary python dependencies using pip:

pip install -r requirements.txt

2. Preprocessing Data

Make sure you have downloaded the datasets into the DATASETS folder. The folder structure should look like this:

  • DATASETS/HAPT Data Set/RawData/...
  • DATASETS/UMAFall Detection Dataset/UMAFall_Dataset/...

Run the preprocessing script to extract the features into the processed_data/ folder:

python run_preprocessing.py

3. Model Training

Train the decision tree and random forest models using the discretized features. The trained models will be saved as .pkl files in the processed_data/ folder.

python run_training.py

4. Deployment Preparation

Port the trained machine learning models to C++ headers ready for ESP32 or Arduino deployment.

python run_deployment_prep.py

The output .h files will be written to processed_data/. These files can be easily included in an ESPIDF, PlatfomrIO, or basically anything that can include C++ headers.

Cite

Consider citing our paper published in Journal of Systems Architecture (JSA) if you use the codebase in your work:

@article{rafee_tinyml_tree_based,
    title = {Decision tree-based real-time personalized Human Activity Recognition and fall detection utilizing cost effective highly resource-constrained microcontrollers},
    journal = {Journal of Systems Architecture},
    volume = {176},
    pages = {103796},
    year = {2026},
    issn = {1383-7621},
    doi = {10.1016/j.sysarc.2026.103796},
    url = {https://doi.org/10.1016/j.sysarc.2026.103796},
    author = {Athar Noor Mohammad Rafee and Md Abu Obaida Zishan and Jannatun Noor},
    keywords = {TinyML, Human Activity Recognition, Low-cost, Low-compute and Low-power, Fall Detection, MCUs}
}

 

Copyright © 2026-present Athar Noor Mohammad Rafee and Contributors.

 

About

Formal codebase for "Decision tree-based real-time personalized Human Activity Recognition and fall detection utilizing cost effective highly resource-constrained microcontrollers" (Journal of Systems Architecture, Volume 176, 1 July 2026, 103796).

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages