Onnx2code
Convert ONNX models to plain C++ code (without dependencies)
Install / Use
/learn @mlomb/Onnx2codeREADME
onnx2code
Generate plain C++ code for inference of ONNX models without dependencies
This project was made as an alternative to a final exam for the assignment "Computer Organization II". You can read the writeup in docs/TP Final onnx2code.pdf (in Spanish).
Model support
The following models have been tested and work as expected.
| Model | Size | |---|---| | mnist | 26 KB | | Super_Resolution | 240 KB | | squeezenet1.1 | 9 MB | | emotion_ferplus | 34 MB | | inception-v2 | 44 MB | | resnet50-caffe2-v1 | 98 MB | | VGG 16 and VGG 16-bn | 527 MB | | VGG 19 and VGG 19-bn | 548 MB | | VGG 19-caffe2 | 561 MB |
- Minimum ONNX opset version: 7
- Quantized models are not supported
Operator support
Only float data type is supported.
| Operator | Attribute support |
|---|---|
| Add, Div, Mul, Sub | ✅ with broadcasting |
| Concat | ✅ with multiple inputs<br/>✅ axis |
| Conv | ✅ bias<br/>✅ stride<br/>✅ padding (and auto_pad)<br/>❌ dilations<br/>❌ depthwise (group != 1) |
| Sum | ✅ with multiple inputs<br/>❌ with broadcasting |
| Relu, Tanh, Sigmoid, Clip | ✅ |
| Gemm | ✅ with bias<br/>❌ transpose A<br/>✅ tranpose B<br/>❌ alpha != 1<br/>❌ beta != 1 |
| Identity | ✅ |
| MaxPool, AveragePool | ✅ stride<br/>✅ padding (and auto_pad)<br/>❌ dilations<br/>❌ storage_order != 0<br/>❌ count_include_pad != 0 |
| Softmax | ✅ stride<br/>✅ axis |
| Transpose | ✅ perm |
Setting up with Docker
We provide a ready to use Docker image:
docker run --rm -it -v $pwd/mnist.onnx:/app/input.onnx:ro -v $pwd/output:/app/output:rw mlomb/onnx2code:latest --variations=im2col,loop-tiling --checks=3
The command above will generate C++ code for the mnist.onnx model in the output folder.
Setting up locally
Prerequisites
- gcc (required if checking models)
- Python 3.10
- pipenv
Clone and install dependencies with pipenv install.
Run
To generate code from an ONNX model, run the following command inside a pipenv shell:
python -m onnx2code --variation=im2col,loop-tiling mnist.onnx output_folder --checks=3
Related Skills
claude-opus-4-5-migration
82.9kMigrate prompts and code from Claude Sonnet 4.0, Sonnet 4.5, or Opus 4.1 to Opus 4.5
model-usage
336.5kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
TrendRadar
49.8k⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的 AI 舆情监控助手与热点筛选工具!聚合多平台热点 + RSS 订阅,支持关键词精准筛选。AI 智能筛选新闻 + AI 翻译 + AI 分析简报直推手机,也支持接入 MCP 架构,赋能 AI 自然语言对话分析、情感洞察与趋势预测等。支持 Docker ,数据本地/云端自持。集成微信/飞书/钉钉/Telegram/邮件/ntfy/bark/slack 等渠道智能推送。
mcp-for-beginners
15.6kThis open-source curriculum introduces the fundamentals of Model Context Protocol (MCP) through real-world, cross-language examples in .NET, Java, TypeScript, JavaScript, Rust and Python. Designed for developers, it focuses on practical techniques for building modular, scalable, and secure AI workflows from session setup to service orchestration.
