TinyMaix is a tiny inference library for microcontrollers (TinyML).
TinyMaix is a tiny inference library for microcontrollers (TinyML).
中文 | English
TinyMaix is a tiny inference Neural Network library specifically for microcontrollers (TinyML).
We design it follow the rule: Easy-to-Use > Portable > Speed > Space
Introduction to tinyML: TinyML
See tested 48 chips and benchmark: benchmark
Good News: Rewarded Porting TinyMaix
Highlights
Run mnist demo on Arduino ATmega328
…Do you want take participate in development of TinyMaix, or discuss with TinyML hobbyist?
Join our telegram group: https://t.me/tinymaix
TinyMaix is design for running AI Neural Network Mdoels on resources limited MCUs, which usually called TinyML
There are many TinyML infer library now, like TFLite micro, microTVM, NNoM, so why we need TinyMaix?
TinyMaix is a weekend hackathons project, so it is simple enough to read though in 30 minutes, and it will help TinyML newbies to understand how is it running.
TinyMaix aims to be a simple TinyML infererence library, it abandon many new features and doesn't use libs like CMSIS-NN.
Following this design goal, now TinyMaix is as simple as 5 files to compile~
We hope TinyMaix can help any MCU run AI Neural Network Mdoels, every one can port it to theirself hardware platform~
Note: Although TinyMaix support multi architecture accelerate, but it still need more effort to balance size and speed.
MNIST is handwritten digit recognition task, it is simple enough for even 8bit MCU like ATmega328.
Try it on PC:
cd examples/mnist
mkdir build
cd build
cmake ..
make
./mnistmbnet (mobilenet v1) is simple classification model for mobile devices, but it is still a little heavy for MCUs.
The model in demo is mobilenet v1 0.25, it input 128x128x3 RGB image, output 1000 classes predict.
It need at least 128KB SRAM and 512KB Flash, STM32F411 is the typical minimum config for this model.
Try run mobilenet
cd examples/mbnet
mkdir build
cd build
cmake ..
make
./mbnetTinyMaix can be installed as a Python package
pip install git+https://github.com/sipeed/TinyMaix@masterTinyMaix requires Tensorflow version ` int input buf
TMPP_UINT2INT //int8: cvt in place; int16: can't cvt in place
TMPP_UINT2FP01 // u8/255.0
TMPP_UINT2FPN11// (u8-128)/128
tm_err_t tm_run (tm_mdl_t* mdl, tm_mat_t* in, tm_mat_t* out);
The core file is those 5 files: tm_model.c, tm_layers.c, tinymaix.h, tm_port.h, arch_xxx.h
If you are using normal mcu without any acceleration instructions, choose arch_cpu.h, otherwise choose corresponding architecture header.
And you should edit tm_port.h to fill your desired configs, all config macro have annotation follow it.
Note TM_MAX_CSIZE,TM_MAX_KSIZE,TM_MAX_KCSIZE will occupy static buffers.
And now just put them into your project, compile it~
There are training scripts in examples/mnist to learn how to train simple mnist models.
Note: you need install TinyMaix first.
After training and save h5 models, you can use scripts in tools to convert to tmdl or c header files.
…Now you have tmdl or c header files, put it into your project to use it~
You can download models from MaixHub or train your AI models online easily with MaixHub, don't need AI knowledge, train your model just click your mouse.
.tmdl file and .h file, use one of them in your code.report.json, report info, json format, we can find labels or anchors in this file, we will use these params in our code. Attention, these params will change in every training, you should copy these params to your code when change model, or you will the result will be wrong.
- There's two type: classification and detection, for first time usage, use classification is recommended.
- There's many backbone, you should select proper backbone according to your MCU's RAM size, the smaller RAM size, should choose the smaller backbone.
- For easier understanding how MaixHub works, at first time you can choose tfjs platform instead of tinymaix to run model on your mobile phone.
maixhub_image_classification demo or maixhub_image_detection demo to run your model.For new platforms, you just need add arch_xxx.h to src dir, and implement functions inside.
Here is the main functions you need implement (sort by importance):
…...
If you want contribute functions to TinyMaix, please read "TinyMaix Design" sections, we only want functions in "Features in design" and "Features maybe added".
If you want commit your port test result, please commit to benchmark.md. You are welcome to port TinyMaix to your chip/boards, it will prove how easy to use TinyMaix run Deeplearning model in MCUs~
If you have question with TinyMaix usage/porting, please feedback Issues in this repo.
If you have bussiness project consulting or private questions, you can send mail to [email protected] or [email protected] (Caesar Wu).
No open issues yet, or sync has not completed.