kraiskil/onnx2c
Open Neural Network Exchange to C compiler.
What it solves
Onnx2c is a compiler that converts ONNX models into pure C code, enabling the execution of neural network inference on microcontrollers (TinyML). It eliminates the dependencies on heavy runtime libraries or dynamic memory allocation, which are typically too resource-constrained for embedded systems.
How it works
The tool reads an ONNX file and generates a single C file containing the model's logic and weights. To ensure compatibility with microcontrollers, it uses compile-time buffer allocation and avoids standard I/O libraries like stdio.h. It includes optimization passes such as tensor unionization to reuse memory and specific optimizations for AVR processors to store constants in instruction memory.
Who it’s for
Developers working with microcontrollers and embedded systems who need to run trained neural networks (exported from frameworks like PyTorch or TensorFlow) without the overhead of a full ML runtime.
Highlights
- Zero Dynamic Allocation: Uses compile-time buffers to avoid heap fragmentation and crashes on small devices.
- C-Standard Compatibility: Requires only the standard C math library, making it highly portable across different C compilers.
- TinyML Optimized: Generates a single C file for easy integration into existing embedded projects.
- Symmetric Support: Supports
float16andbfloat16data types via GCC and Clang extensions. - Memory Efficient: Includes optimizations to reduce RAM usage by marking constant tensors as
constto keep them in flash memory.
Related
- Project
- Project
- Project
- Project
- Project