Skip to content

MaxRondelli/Human-Activity-Recognition-with-LSTM-on-M5Stack

Repository files navigation

Human Activity Recognition with LSTM on M5Stack

This project implements Human Activity Recognition (HAR) using a Long Short-Term Memory (LSTM) neural network on an M5Stack Gray device. The model is trained on the UCI Human Activity Recognition dataset and deployed on the M5Stack for real-time inference using its built-in IMU sensor.

Installation

  1. Clone this repository:
git clone https://github.com/MaxRondelli/Human-Activity-Recognition-with-LSTM-on-M5Stack.git
  1. Install the required Python packages:
pip install -r requirements.txt
  1. Set up the Arduino IDE with M5Stack support following the official M5Stack documentation.
  2. Download and include the two libraries necessary to run inference on the IoT device.
#include <M5Stack.h>
#include <TensorFlowLite_ESP32.h>

TensorFlowLite for ESP32 is necessary to load and interpreter the LSTM model.

Usage

  1. Download the UCI HAR dataset.
cd data
python download_dataset.py
  1. Start the training.
python main.py
  1. The best model and all the statistics about the training will be saved in the folder results/that_specific_run/.
  2. Convert the best.pth model to TensorFlowLite format. Look at the given path for the variable BEST_MODEL in the class pytorch2tflite.py
python pytorch2tflite.py
  1. Convert the edge_model.tflite to .h format. It must be in the following format to be load on the M5Stack device.
xxd -i edge_model.tflite > edge_model.h
  1. Once you have the converted model in .h format, add the attribute const to the model the variables in the model. So change from:
unsigned char edge_model_tflite[] = { model_inside_the_brackets }
unsigned int edge_model_tflite_len = 70912;

to

const unsigned char edge_model_tflite[] = { model_inside_the_brackets }
const unsigned int edge_model_tflite_len = 70912;
  1. To run the inference on M5Stack, move the edge_model.h inside the same folder where the .ino file is. Include the model inside the file and run the code.

Performance

Model's performance on the left and M5Stack inference on the right.

Model's Confusion Matrix M5Stack Inference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published