{"id":13504544,"url":"https://github.com/majianjia/nnom","last_synced_at":"2025-03-29T22:30:53.385Z","repository":{"id":37405461,"uuid":"166869630","full_name":"majianjia/nnom","owner":"majianjia","description":"A higher-level Neural Network library for microcontrollers.","archived":false,"fork":false,"pushed_at":"2024-04-08T03:15:10.000Z","size":27147,"stargazers_count":936,"open_issues_count":83,"forks_count":246,"subscribers_count":45,"default_branch":"master","last_synced_at":"2024-11-01T02:34:11.932Z","etag":null,"topics":["embedded","iot","machine-learning","mcu","microcontroller","ml","neural-networks","nnom"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/majianjia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-21T19:38:30.000Z","updated_at":"2024-10-31T07:22:35.000Z","dependencies_parsed_at":"2023-01-19T11:47:47.983Z","dependency_job_id":"fadc7404-b1c1-49e6-978c-f8c53393fa8d","html_url":"https://github.com/majianjia/nnom","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majianjia%2Fnnom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majianjia%2Fnnom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majianjia%2Fnnom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/majianjia%2Fnnom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/majianjia","download_url":"https://codeload.github.com/majianjia/nnom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254077,"owners_count":20747946,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded","iot","machine-learning","mcu","microcontroller","ml","neural-networks","nnom"],"created_at":"2024-08-01T00:00:45.439Z","updated_at":"2025-03-29T22:30:51.246Z","avatar_url":"https://github.com/majianjia.png","language":"C","funding_links":[],"categories":["nn","Machine Learning \u0026 AI on MCU","Uncategorized","微控制器 MCU 端","Packages","Data processing"],"sub_categories":["USB","Uncategorized","Awesome-Embedded Repository","AI","AI ML"],"readme":"\n# Neural Network on Microcontroller (NNoM)\n[![Build Status](https://travis-ci.com/majianjia/nnom.svg?branch=master)](https://app.travis-ci.com/github/majianjia/nnom)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![DOI](https://zenodo.org/badge/166869630.svg)](https://zenodo.org/badge/latestdoi/166869630)\n\nNNoM is a high-level inference Neural Network library specifically for microcontrollers. \n\n[[English Manual]](https://majianjia.github.io/nnom/) [[中文简介]](docs/rt-thread_guide.md) \n\n**Highlights**\n\n- Deploy Keras model to NNoM model with one line of code.\n- Support complex structures; Inception, ResNet, DenseNet, Octave Convolution...\n- User-friendly interfaces.\n- High-performance backend selections.\n- Onboard pre-compiling - zero interpreter performance loss at runtime. \n- Onboard evaluation tools; Runtime analysis, Top-k, Confusion matrix... \n\nThe structure of NNoM is shown below:\n![](docs/figures/nnom_structure.png)\n\nMore detail avaialble in [Development Guide](docs/guide_development.md)\n\nDiscussions welcome using [issues](https://github.com/majianjia/nnom/issues). \nPull request welcome. QQ/TIM group: 763089399.\n\n## Latest Updates - v0.4.x\n\n**Recurrent Layers (RNN) (0.4.1)**\n\nRecurrent layers **(Simple RNN, GRU, LSTM)** are implemented in version 0.4.1. Support `statful` and `return_sequence` options. \n\n**New Structured Interface (0.4.0)** \n\nNNoM has provided a new layer interface called **Structured Interface**, all marked with `_s` suffix. which aims to use one C-structure to provided all the configuration for a layer. Different from the Layer API which is human friendly, this structured API are more machine friendly. \n\n**Per-Channel Quantisation (0.4.0)**\n\nThe new structred API supports per-channel quantisation (per-axis) and dilations for **Convolutional layers**. \n\n**New Scripts (0.4.0)**\n\nFrom 0.4.0, NNoM will switch to structured interface as default to generate the model header `weights.h`. The scripts corresponding to structured interfaces are `nnom.py` while the Layer Interface corresponding to `nnom_utils.py`.\n\n## Licenses\n\nNNoM is released under Apache License 2.0 since nnom-V0.2.0. \nLicense and copyright information can be found within the code.\n\n## Why NNoM?\nThe aims of NNoM is to provide a light-weight, user-friendly and flexible interface for fast deploying on MCU.\n\nNowadays, neural networks are **wider**, **deeper**, and **denser**.\n![](docs/figures/nnom_wdd.png)\n\u003e[1] Szegedy, C., Liu, W., Jia, Y., Sermanet, P., Reed, S., Anguelov, D., ... \u0026 Rabinovich, A. (2015). Going deeper with convolutions. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 1-9).\n\u003e\n\u003e[2] He, K., Zhang, X., Ren, S., \u0026 Sun, J. (2016). Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 770-778).\n\u003e\n\u003e[3] Huang, G., Liu, Z., Van Der Maaten, L., \u0026 Weinberger, K. Q. (2017). Densely connected convolutional networks. In Proceedings of the IEEE conference on computer vision and pattern recognition (pp. 4700-4708).\n\nAfter 2014, the development of Neural Networks are more focus on structure optimising to improve efficiency and performance, which is more important to the small footprint platforms such as MCUs. \nHowever, the available NN libs for MCU are too low-level which make it sooooo difficult to use with these complex strucures. \n\nTherefore, we build NNoM to help embedded developers for faster and simpler deploying NN model directly to MCU. \n\u003e NNoM will manage the strucutre, memory and everything else for the developer. All you need to do is feeding your new measurements and getting the results. \n\n## Installing\n\nNNoM can be installed as a Python package\n\n```\npip install git+https://github.com/majianjia/nnom@master\n```\n\nNNoM requires [Tensorflow](https://www.tensorflow.org/) version `\u003c= 2.14`.\nThere are multiple options for how to install this, see the TensorFlow documentation.\n\nFor example:\n```\npip install 'tensorflow-cpu\u003c=2.14.1'\n```\n\nNOTE: Tensorflow 2.14 supports up until Python 3.11.\nHowever, *Python 3.12 is not supported*.\n\n## Accessing C files\n\nThe C headers and source code in NNoM are distributed in the `nnom_core` Python package.\nYou can find its location by running the following command.\n```\npython -c \"import nnom_core; print(nnom_core.__path__[0])\"\n```\nIn your build system, add the `inc/` and `port/` directories as include directories,\nand compile the the `src/*.c` files.\n\n## Documentations\n\n**Guides**\n\n[5 min to NNoM Guide](docs/guide_5_min_to_nnom.md)\n\n[The temporary guide](docs/A_Temporary_Guide_to_NNoM.md)\n\n[Porting and optimising Guide](docs/Porting_and_Optimisation_Guide.md) \n\n[RT-Thread Guide(Chinese)](https://majianjia.github.io/nnom/rt-thread_guide/)\n\n[RT-Thread-MNIST example (Chinese)](docs/example_mnist_simple_cn.md)\n\n\n\n## Performance \n\nThere are many articles compared NNoM with other famous MCU AI tools, such as TensorFlow LiteSTM32Cube.AI .etc. \n\n**Raphael Zingg etc** from Zurich University of Applied Sciences compare nnom with tflite, cube, and e-Ai in their paper  [\"Artificial Intelligence on Microcontrollers\"](https://github.com/InES-HPMM/Artificial_Intelligence_on_Microcontrollers/blob/master/Artificial_Intelligence_on_Microcontrollers.pdf) blog https://blog.zhaw.ch/high-performance/2020/05/14/artificial-intelligence-on-microcontrollers/\n\n![performance-comparison-tflite-cubeai-eai](docs/figures/performance-comparison-tflite-cubeai-eai.png)\n\n**Butt Usman Ali** from POLITECNICO DI TORINO, did below comparison in [the thesis: On the deployment of Artificial Neural Networks (ANN) in low \ncost embedded systems](https://webthesis.biblio.polito.it/19692/1/tesi.pdf)\n\n![performance-comparison-tflite-cubeai](docs/figures/performance-comparison-tflite-cubeai.png)\n\nBoth articles shows that NNoM is not only comparable with other popular NN framework but with faster inference time and sometime less memory footprint. \n\n**Note:** These graphs and tables are credited to their authors. Please refer the their original papers for details and copyright. \n\n\n\n## Examples\n\n**Documented examples**\n\nPlease check [examples](https://github.com/majianjia/nnom/tree/master/examples) and choose one to start with. \n\n## Available Operations\n\n[[API Manual]](https://majianjia.github.io/nnom/)\n\n\u003e *Notes: NNoM now supports both HWC and CHW formats. Some operation might not support both format currently. Please check the tables for the current status. *\n\n\n**Core Layers**\n\n| Layers | Struct API |Layer API|Comments|\n| ------ |-------- |------|------|\n| Convolution  |conv2d_s()|Conv2D()|Support 1/2D, support dilations (New!)|\n| ConvTransposed (New!) |conv2d_trans_s()|Conv2DTrans()|Under Dev. |\n| Depthwise Conv |dwconv2d_s()|DW_Conv2D()|Support 1/2D|\n| Fully-connected |dense_s()| Dense()| |\n| Lambda |lambda_s()| Lambda() |single input / single output anonymous operation| \n| Batch Normalization |N/A| N/A| This layer is merged to the last Conv by the script|\n| Flatten|flatten_s()| Flatten()| |\n| Reshape (New!)|reshape_s()| N/A| |\n| SoftMax|softmax_s()| SoftMax()| Softmax only has layer API| \n| Activation|N/A| Activation()|A layer instance for activation|\n| Input/Output |input_s()/output_s()| Input()/Output()| |\n| Up Sampling |upsample_s()|UpSample()||\n| Zero Padding | zeropadding_s()|ZeroPadding()||\n| Cropping |cropping_s() |Cropping()||\n\n**RNN Layers**\n\n| Layers | Status | Struct API |Comments|\n| ------ | ------ | ------| ------|\n| Recurrent NN Layer(New!) | Alpha | rnn_s()| Layer wrapper of RNN|\n| Simple Cell (New!) | Alpha | simple_cell_s()||\n| GRU Cell (New!) | Alpha | gru_cell_s()| Gated Recurrent Network |\n| LSTM Cell (New!) | Alpha| lstm_s()| Long Short-Term Memory |\n\n**Activations**\n\nActivation can be used by itself as layer, or can be attached to the previous layer as [\"actail\"](docs/A_Temporary_Guide_to_NNoM.md#addictionlly-activation-apis) to reduce memory cost.\n\nThere is no structred API for activation currently, since activation are not usually used as a layer.\n\n| Actrivation | Struct API |Layer API|Activation API|Comments|\n| ------ |--|--|--|--|\n| ReLU  | N/A |ReLU()|act_relu()||\n| Leaky ReLU (New!) | N/A |LeakyReLU()|act_leaky_relu()||\n| Adv ReLU(New!) | N/A |N/A|act_adv_relu()|advance ReLU, Slope, max, threshold|\n| TanH | N/A |TanH()|act_tanh()||\n| Hard TanH (New!)| N/A |TanH()||backend only|\n|Sigmoid|N/A| Sigmoid()|act_sigmoid()||\n|Hard Sigmoid (New!)|N/A| N/A| N/A|backend only|\n\n**Pooling Layers**\n\n| Pooling | Struct API|Layer API|Comments|\n| ------ |--------|----|----|\n| Max Pooling |maxpool_s()|MaxPool()||\n| Average Pooling |avgpool_s()|AvgPool()||\n| Sum Pooling |sumpool_s()|SumPool()||\n| Global Max Pooling|global_maxpool_s()|GlobalMaxPool()||\n| Global Average Pooling |global_avgpool_s()|GlobalAvgPool()||\n| Global Sum Pooling |global_sumpool_s()|GlobalSumPool()|dynamic output shift|\n\n**Matrix Operations Layers**\n\n| Matrix |Struct API |Layer API|Comments|\n| ------ |--|--|--|\n| Concatenate |concat_s()| Concat()| Concatenate through any axis|\n| Multiple  |mult_s()|Mult()||\n| Addition  |add_s()|Add()||\n| Substraction  |sub_s()|Sub()||\n\n\n## Dependencies\n\nNNoM now use the local pure C backend implementation by default. Thus, there is no special dependency needed. \n\nHowever, You will need to enable `libc` for dynamic memory allocation `malloc(), free(), and memset()`. Or you can port to the equivalent memory method in your system.  \n\n\n## Optimization\n[CMSIS-NN/DSP](https://github.com/ARM-software/CMSIS_5/tree/develop/CMSIS/NN) is an optimized backend for ARM-Cortex-M4/7/33/35P. You can select it for up to 5x performance compared to the default C backend. NNoM will use the equivalent method in CMSIS-NN if the condition met. \n\nPlease check [Porting and optimising Guide](docs/Porting_and_Optimisation_Guide.md) for detail. \n\n## Known Issues\n### The Converter do not support implicitly defined activations\nThe script currently does not support implicit act:\n~~~\nx = Dense(32, activation=\"relu\")(x)\n~~~\nUse the explicit activation instead. \n~~~\nx = Dense(32)(x)\nx = Relu()(x)\n~~~\n\n## Tips - improving accuracy\n- Attaching an BatchNormalization after each convolutional layer limit the activation range thus help quantisation. BN add no extra computation in NNoM. \n- Dont train too much epoch. Large epoch number increases extreme number in activation -\u003e lower the quantisation resolution.\n- Leave enough data for bottleneck - do not compress data at before the output of a model, infomation will be lost when it is quantised. \n\n## Contacts\nJianjia Ma\nmajianjia@live.com\n\nAlso find me for field supports. \n\n## Citation are required in publication\nPlease contact me using above details if you have any problem. \n\nExample:\n~~~\n@software{jianjia_ma_2020_4158710,\n  author       = {Jianjia Ma},\n  title        = {{A higher-level Neural Network library on Microcontrollers (NNoM)}},\n  month        = oct,\n  year         = 2020,\n  publisher    = {Zenodo},\n  version      = {v0.4.2},\n  doi          = {10.5281/zenodo.4158710},\n  url          = {https://doi.org/10.5281/zenodo.4158710}\n}\n~~~\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajianjia%2Fnnom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmajianjia%2Fnnom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmajianjia%2Fnnom/lists"}