libonnx

xbootMIT更新放缓

纯 C99 实现的轻量级 ONNX 推理引擎,专为嵌入式设备设计,支持硬件加速,让单片机也能跑深度学习模型。

A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support.

暂无版本656star114fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
cd libonnx
make
硬件要求按 README 说明

README 未说明具体显存、CPU 或 GPU 型号要求,仅说明面向嵌入式设备并支持硬件加速

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

纯 C99 实现的轻量级 ONNX 推理引擎,可移植到嵌入式设备并支持硬件加速

纯 C99 实现的轻量级 ONNX 推理引擎,专为嵌入式设备设计,支持硬件加速,让单片机也能跑深度学习模型。

核心能力

  • 纯 C99 实现,.c/.h 文件可直接加入工程编译
  • 通过 resolver_t 数组接入硬件加速
  • 用 onnx_context_alloc_from_file 加载模型文件
  • 用 onnx_tensor_search 按名称查找输入输出张量
  • 支持 xxd 转成字节数组后用 onnx_context_alloc 加载

容易踩的坑

编译 mnist 示例需先安装 SDL2 和 SDL2 GFX 库;部分算子尚未实现,非 tests/model 目录的测试可能失败;交叉编译需通过 CROSS_COMPILE 指定工具链路径

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Libonnx

    A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support.

    Getting Started

    The library's .c and .h files can be dropped into a project and compiled along with it. Before use, should be allocated struct onnx_context_t * and you can pass an array of struct resolver_t * for hardware acceleration.

    The filename is path to the format of onnx model.

    struct onnx_context_t * ctx = onnx_context_alloc_from_file(filename, NULL, 0);
    

    Then, you can get input and output tensor using onnx_tensor_search function.

    struct onnx_tensor_t * input = onnx_tensor_search(ctx, "input-tensor-name");
    struct onnx_tensor_t * output = onnx_tensor_search(ctx, "output-tensor-name");
    

    When the input tensor has been setting, you can run inference engine using onnx_run function and the result will putting into the output tensor.

    onnx_run(ctx);
    

    Finally, you must free struct onnx_context_t * using onnx_context_free function.

    onnx_context_free(ctx);
    

    Compilation Instructions

    Just type make at the root directory, you will see a static library and some binary of examples and tests for usage.

    cd libonnx
    make
    

    To compile the mnist example, you will have to install SDL2 and SDL2 GFX. On systems like Ubuntu run

        apt-get install libsdl2-dev libsdl2-gfx-dev
    

    to install the required Simple DirectMedia Layer libraries to run the GUI.

    Cross compilation example (for arm64)

    Run make CROSS_COMPILE=path/to/toolchains/aarch64-linux-gnu- at the root directory to compile all libraries, tests and examples for the platform.

    Change CROSS_COMPILE to point the toolchains that you plan to use.

    How to run examples

    After compiling all the files, you can run an example by using:

    cd libonnx/examples/hello/output
    ./hello
    

    Screenshots

    Running tests

    To run tests, for example on those in the tests/model folder use:

    cd libonnx/tests/output
    ./tests ../model
    

    Here is the output:

    [mnist_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                              [OKAY]
    [mnist_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_1)                                                              [OKAY]
    [mnist_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_2)                                                              [OKAY]
    [mobilenet_v2_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                       [OKAY]
    [mobilenet_v2_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_1)                                                       [OKAY]
    [mobilenet_v2_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_2)                                                       [OKAY]
    [shufflenet_v1_9](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                      [OKAY]
    [shufflenet_v1_9](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_1)                                                      [OKAY]
    [shufflenet_v1_9](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_2)                                                      [OKAY]
    [squeezenet_v11_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                     [OKAY]
    [squeezenet_v11_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_1)                                                     [OKAY]
    [squeezenet_v11_7](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_2)                                                     [OKAY]
    [super_resolution_10](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                  [OKAY]
    [tinyyolo_v2_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_0)                                                        [OKAY]
    [tinyyolo_v2_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_1)                                                        [OKAY]
    [tinyyolo_v2_8](https://github.com/xboot/libonnx/blob/HEAD/test_data_set_2)                                                        [OKAY]
    

    Note that running the test on the other folders may not succeed. Some operators have not been implemented, look bat the notes section for more info.

    Notes

    • This library based on the onnx version v1.17.0 with the newest opset 24 support. The supported operator table in the documents directory.
    • Checkout the tools folder for help with ONNX model files.
    • You can use xxd -i <filename.onnx> (on Linux) to convert your onnx model into a unsigned char array and then use the function onnx_context_alloc to use it. This is how the models are loaded in the examples - hello and mnist.

    Links

    License

    This library is free software; you can redistribute it and or modify it under the terms of the MIT license. See MIT License for details.