This repository contains the complete pipeline for training, quantizing, and deploying Human Activity Recognition (HAR) models on RISC-V architectures. The project utilizes deep learning architectures (CNN, GRU, LSTM) and TensorFlow Lite for Microcontrollers (TFLite Micro) to enable efficient, edge-based inference.
The goal of this project is to create highly optimized HAR models that can run on resource-constrained RISC-V microcontrollers. The pipeline covers:
- Data Preprocessing: Handling and scaling raw sensor data (e.g., accelerometer, gyroscope).
- Model Training & Evaluation: Training models like CNN and CNN-GRU, including Leave-One-Subject-Out (LOSO) cross-validation for robustness.
- Quantization: Converting models to
INT8format via TFLite to dramatically reduce memory footprint and latency. - RISC-V Simulation & Execution: Compiling the quantized models with TFLite Micro and running them in a RISC-V environment (using simulators like Spike).
- Real-time Demonstrations: Providing websocket-based streaming tools to visualize activity recognition in real-time.
train_*.py/evaluate_*.py: Scripts used to train the Keras models, evaluate their accuracy, and convert/quantize them to TFLite formats.main.cc,model_data.cc,test_data.h: C++ source files for initializing TFLite Micro, loading the quantized model arrays, and performing inference.models/: Contains the generated.kerasand.tflitemodel files along with their training history and performance graphs.websocket_har_demo/: A real-time web application to stream sensor data (e.g., via Phyphox) and visualize live predictions.exhibition_showcase/: Front-end components for demonstrating the project's capabilities.
To train the CNN model with quantization-aware strategies or standard pipelines, use the provided Python scripts:
python train_cnn_tinyml.py
python train_realworld_cnn_loso.pyModels will be evaluated and exported as .keras and .tflite artifacts in the models/ directory.
Export the quantized TFLite model to a C-byte array (e.g., model_data.cc). Then, compile the main.cc with the TFLite Micro library and run the executable in your RISC-V simulator.
To launch the real-time websocket demo, navigate to the websocket_har_demo directory to start the backend server and frontend dashboard.
- Python 3.8+ (TensorFlow, Keras, NumPy, Pandas, Scikit-Learn, Matplotlib)
- RISC-V Toolchain (e.g.,
riscv64-unknown-elf-gcc) - Spike RISC-V Simulator
- TensorFlow Lite for Microcontrollers (TFLite Micro)