https://github.com/ariel-os/ariel-microflow-ml
Generic Tiny Machine Learning pipeline for boards supported by Ariel OS
https://github.com/ariel-os/ariel-microflow-ml
edgeai machine-learning microcontroller rust tinyml
Last synced: about 22 hours ago
JSON representation
Generic Tiny Machine Learning pipeline for boards supported by Ariel OS
- Host: GitHub
- URL: https://github.com/ariel-os/ariel-microflow-ml
- Owner: ariel-os
- Created: 2026-06-09T10:13:49.000Z (18 days ago)
- Default Branch: main
- Last Pushed: 2026-06-09T15:08:27.000Z (18 days ago)
- Last Synced: 2026-06-09T17:11:48.776Z (18 days ago)
- Topics: edgeai, machine-learning, microcontroller, rust, tinyml
- Language: Jupyter Notebook
- Homepage:
- Size: 410 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ariel OS Machine Learning with Microflow
This repository provides a generic Tiny ML pipeline for [Ariel OS](https://ariel-os.github.io/ariel-os/)
using [MicroFlow](https://github.com/matteocarnelos/microflow-rs)
as the inference engine for full Rust, `no_std` Ariel OS compatible, quantized TFLite or PyTorch models.
## Prerequisites
- Rust toolchain (stable + the embedded target your board needs)
- [Ariel OS getting started](https://ariel-os.github.io/ariel-os/dev/docs/book/getting-started.html) (`laze`, `probe-rs`, etc.)
- [uv](https://docs.astral.sh/uv/) for the Python notebooks (env and dependences management)
## Workflow
### 1. Train and export a `.tflite`
TensorFlow and PyTorch are kept in separate uv projects to avoid version conflicts.
Pick one(here TensorFlow for example), then:
```
cd building_tf # or building_torch
uv sync
```
Run the notebook. It downloads MNIST automatically (Keras /
torchvision cache) and writes an INT8-quantized model into `models/` at the
repo root — exactly where `src/main.rs`'s `#[model("models/…")]` attribute
looks for it.
> Only **quantized** models are supported. The notebook uses per-tensor INT8
> quantization, which is what MicroFlow expects.
`models_provided/mobilenetv1.tflite` is the pre-baked person-detection model
from MicroFlow's own repo — some ops (padding, batch-norm) are baked into the
weights so MicroFlow can consume it.
### 2. Build and flash
```
laze build -b run --features
```
The code in the repo provides two example models: **LeNet5** (MNIST digits) trained from either
TensorFlow or PyTorch, and **MobileNetV1** (person detection) from the MicroFlow repo.
In practice, pick one model features out of the following list:
| feature | model |
|----------------|------------------------------------------------------------|
| `lenet5qtf` | LeNet5 trained with TensorFlow (`models/lenet5_quantized_tf.tflite`) |
| `lenet5qtorch` | LeNet5 trained with PyTorch (`models/lenet5_quantized_torch.tflite`) |
| `mobilenetv1` | Person detection (`models_provided/mobilenetv1.tflite`) |
For example, on a Raspberry Pi Pico 2 W for LeNet5:
```
laze build -b rpi-pico2-w run --features lenet5qtf
```
Stack sizes for the main thread are tuned in `src/main.rs` and
`laze-project.yml`.
Note that MobileNetV1 in particular needs a large stack (320 KiB).
## Benchmarking
Inspect the built binary:
```
arm-none-eabi-size build/bin//cargo//release/ariel-microflow-ml
nm --print-size --size-sort --demangle=rust --radix=d
```
Per-inference timing is logged at runtime (`info!` lines, averaged over 4 runs).
Reference numbers on a Raspberry Pi Pico 2 W, averaged over 4 runs ; thread stack is the minimum to set:
| model | time (ms) | main thread stack (KiB) |
|-------------|-----------|-------------------------|
| lenet5q | 53 | 14 |
| mobilenetv1 | 3523 | 320 |
## Remarks & Next steps
### MicroFlow op support
MicroFlow only implements a subset of TFLite ops (Conv2D, DepthwiseConv2D,
FullyConnected, AveragePool2D, Reshape, Softmax, Transpose at the current day ). If your model uses anything else, the build will fail at the
`#[model(...)]` macro with an "unimplemented operator" message.
See the upstream repo for the current list and to contribute new ops:
### Notebook outputs
Notebook outputs are stripped at commit time via a `nbstripout` git filter — after cloning, run `pipx install nbstripout && nbstripout --install` once.
---
---
## Further reading
For more information on Microflow, you can read this paper
[M. Carnelos, F Pasti, N Bellotto, "MicroFlow: An Efficient Rust-Based Inference Engine for TinyML," Elsevier Internet of Things, 2025](https://arxiv.org/pdf/2409.19432).
For more information on Ariel OS, your can read this other paper [E. Frank et al. "Ariel OS: An Embedded Rust Operating System for Networked Sensors & Multi-Core Microcontrollers", IEEE DCOSS-IoT, 2025](https://arxiv.org/pdf/2504.19662).