Skip to main content

FogML

Due to the development of IoT solutions, we can observe the constantly growing number of these devices in almost every aspect of our lives. The machine learning may improve increase their intelligence and smartness. Unfortunately, the highly regarded programming libraries consume to much resources to be ported to the embedded processors.

The FogML is a set of tools enabling TinyML on microcontrollers as low resource-limited as ARM M0 cores. In contrast to many other frameworks, the FogML utilises classic machine learning methods such as density-based anomaly detection and classifiers based on Bayesian networks, decision forests and vanilla MLP. In addition, it supports off-device learning for the classification problem and on-device learning for anomaly detection. The active learning anomaly detection is based on reservoir sampling and outlier detection algorithms which are trained directly on the device. The dedicated library performs the time series processing on the devices, computing the feature vector consisting of RMS, FFT, amplitude and other low-level signal metrics. One of the techniques used in FogML is source code generation of the inferencing functions for embedded devices. It leads to a much smaller memory footprint than for more computationally advanced solutions such as deep neural networks.

Classification pipeline

The structure of the project is as follows:

  • the src folder contains the source code generators for machine learning models i.e.: naive bayes, decision trees/forrest and neural nets;
  • the example folder contains the simple examples and the MNIST digit recognition for Arduino board and the simple TFT touchscreen.

Examples of anomaly detection and classification algorithms provided by the FogML project for embedded devices:

  • FogML-SDK [https://github.com/tszydlo/fogml_sdk]
  • FogML Arduino [https://github.com/tszydlo/FogML-Arduino]
  • FogML Zephyr OS [https://github.com/tszydlo/FogML-Zephyr]
  • FogML ISPU [https://github.com/tszydlo/FogML-ISPU]

Example of connectivity and device management provided by LwM2M protocol:

  • FogML-Zephyr-LwM2M [https://github.com/tszydlo/FogML-Zephyr-LwM2M]

TinyML lifecycle Management with FOTA using LwM2M protocol:

  • FogML-Zephyr-FOTA [https://github.com/tszydlo/FogML-Zephyr-FOTA]

Usage

pip install fogml

Example

from sklearn import datasets, tree

from fogml.generators import GeneratorFactory

iris = datasets.load_iris()
X = iris.data
y = iris.target

clf = tree.DecisionTreeClassifier(random_state=3456)
clf.fit(X, y)
print( 'accuracy: ',clf.score(X,y))

factory = GeneratorFactory()
generator = factory.get_generator(clf)
generator.generate()

Reinforcement Learning

import gym

from fogml.generators import GeneratorFactory
from fogml.rl.qlearning import QLearning, QStatesIntervals

env = gym.make('MountainCar-v0')

#create QStates discretizer table using QStatesIntervals()
stateSpace = [
    [-1.2, 0.6, 20],
    [-0.07, 0.07, 20]
]
qStates = QStatesIntervals(stateSpace)

#create QLearning agent
qAgent = QLearning(qStates.getStates(), env.action_space.n)

for episode in range(EPISODES):
    #TODO Train the model
    #see examples

factory = GeneratorFactory()

generatorQAgent = factory.get_generator(qAgent)
generatorQStates = factory.get_generator(qStates)

generatorQAgent.generate(fname='FogML_RL_Arduino\qlearning_model_test.c')
generatorQStates.generate(fname = 'FogML_RL_Arduino\qstates_discretizer_test.c')

See it in action: https://www.youtube.com/watch?v=yEr5tjBrY70

FogML research

If you think that the project is interesting to you, please cite the papers:

Tomasz Szydlo, Marcin Nagy, Device management and network connectivity as missing elements in TinyML landscape, TinyML Research Summit 2023

Tomasz Szydlo, Online Anomaly Detection Based On Reservoir Sampling and LOF for IoT devices, CoRR abs/2206.14265 (2022)

Tomasz Szydlo, Prem Prakash Jayaraman, Yinhao Li, Graham Morgan, Rajiv Ranjan, TinyRL: Towards Reinforcement Learning on Tiny Embedded Devices. CIKM 2022, 4985-4988

Tomasz Szydlo, Joanna Sendorek, Robert Brzoza-Woch, Enabling machine learning on resource constrained devices by source code generation of the learned models, ICCS 2018: 682-694

Press

https://blog.arduino.cc/2022/07/22/industrial-iot-anomaly-detection-on-microcontrollers/

Metadata

Release files for fogml 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fogml 0.0.9
File Size Uploaded
fogml-0.0.9.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fogml 0.0.9
File Interpreter ABI Platform
fogml-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 61.2 kB

Release files / fogml-0.0.9.tar.gz

Download URL fogml-0.0.9.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f82c4da8ac4da75e8d0c0d28cd7aed1839148fe0d413b9a812e03278250d6883
BLAKE2b-256 checksum
How to use checksums
416cd9551f0590329fa545f4cea949a8fb2fc52970f0aa4daa3028c089948b3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.8.18

Release files / fogml-0.0.9-py3-none-any.whl

Download URL fogml-0.0.9-py3-none-any.whl
Size 37.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20a91d01caff39a2ef981b67e8f835b0d0c771faab98d929fc9b93b4c27f939c
BLAKE2b-256 checksum
How to use checksums
10b685d939cd939d689fff5ea793eeda9152767c977261f73d063db516214211
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page