{"id":13601199,"url":"https://github.com/xboot/libonnx","last_synced_at":"2025-05-15T11:09:10.683Z","repository":{"id":47534054,"uuid":"303868944","full_name":"xboot/libonnx","owner":"xboot","description":"A lightweight, portable pure C99 onnx inference engine for embedded devices with hardware acceleration support.","archived":false,"fork":false,"pushed_at":"2024-11-20T02:31:56.000Z","size":95683,"stargazers_count":611,"open_issues_count":16,"forks_count":111,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-14T19:59:13.223Z","etag":null,"topics":["ai","baremetal","c","dedeep-neural-networks","deep-learning","embedded","embedded-systems","hardware-acceleration","inference","library","lightweight","machine-learning","neural-network","onnx","portable"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xboot.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":"2020-10-14T01:20:39.000Z","updated_at":"2025-04-09T03:06:12.000Z","dependencies_parsed_at":"2023-01-19T23:04:19.828Z","dependency_job_id":"5e93330a-1dd2-45e2-b18b-a33ca32bc4fe","html_url":"https://github.com/xboot/libonnx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xboot%2Flibonnx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xboot%2Flibonnx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xboot%2Flibonnx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xboot%2Flibonnx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xboot","download_url":"https://codeload.github.com/xboot/libonnx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328386,"owners_count":22052632,"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":["ai","baremetal","c","dedeep-neural-networks","deep-learning","embedded","embedded-systems","hardware-acceleration","inference","library","lightweight","machine-learning","neural-network","onnx","portable"],"created_at":"2024-08-01T18:00:58.129Z","updated_at":"2025-05-15T11:09:05.674Z","avatar_url":"https://github.com/xboot.png","language":"C","funding_links":[],"categories":["C","C语言","Lighter and Deployment Frameworks","Data processing","Data \u0026 Science"],"sub_categories":["[Tools](#tools-1)","AI ML","Machine Learning Framework"],"readme":"\n\n***\n# Libonnx\nA lightweight, portable pure `C99` `onnx` `inference engine` for embedded devices with hardware acceleration support.\n\n## Getting Started\nThe 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.\n\nThe filename is path to the format of `onnx` model.\n\n```c\nstruct onnx_context_t * ctx = onnx_context_alloc_from_file(filename, NULL, 0);\n```\n\nThen, you can get input and output tensor using `onnx_tensor_search` function.\n\n```c\nstruct onnx_tensor_t * input = onnx_tensor_search(ctx, \"input-tensor-name\");\nstruct onnx_tensor_t * output = onnx_tensor_search(ctx, \"output-tensor-name\");\n```\n\nWhen the input tensor has been setting, you can run inference engine using `onnx_run` function and the result will putting into the output tensor.\n\n```c\nonnx_run(ctx);\n```\n\nFinally, you must free `struct onnx_context_t *` using `onnx_context_free` function.\n\n```c\nonnx_context_free(ctx);\n```\n\n## Compilation Instructions\n\nJust type `make` at the root directory, you will see a static library and some binary of [examples](examples) and [tests](tests) for usage.\n\n```shell\ncd libonnx\nmake\n```\n\nTo compile the `mnist` example, you will have to install SDL2 and SDL2 GFX. On systems like Ubuntu run\n```shell\n    apt-get install libsdl2-dev libsdl2-gfx-dev\n```\nto install the required Simple DirectMedia Layer libraries to run the GUI.\n\n#### Cross compilation example (for `arm64`)\n\nRun `make CROSS_COMPILE=path/to/toolchains/aarch64-linux-gnu-` at the root directory to compile all libraries, tests and examples for the platform.\n\nChange `CROSS_COMPILE` to point the toolchains that you plan to use.\n\n\n#### How to run examples\n\nAfter compiling all the files, you can run an example by using:\n\n```shell\ncd libonnx/examples/hello/output\n./hello\n```\n\n## Screenshots\n* [Mnist handwritten digit prediction](examples/mnist)\n![Mnist handwritten digit prediction](documents/images/mnist.gif)\n\n## Running tests\n\nTo run tests, for example on those in the `tests/model` folder use:\n\n```shell\ncd libonnx/tests/output\n./tests ../model\n```\n\nHere is the output:\n```shell\n[mnist_8](test_data_set_0)                                                              [OKAY]\n[mnist_8](test_data_set_1)                                                              [OKAY]\n[mnist_8](test_data_set_2)                                                              [OKAY]\n[mobilenet_v2_7](test_data_set_0)                                                       [OKAY]\n[mobilenet_v2_7](test_data_set_1)                                                       [OKAY]\n[mobilenet_v2_7](test_data_set_2)                                                       [OKAY]\n[shufflenet_v1_9](test_data_set_0)                                                      [OKAY]\n[shufflenet_v1_9](test_data_set_1)                                                      [OKAY]\n[shufflenet_v1_9](test_data_set_2)                                                      [OKAY]\n[squeezenet_v11_7](test_data_set_0)                                                     [OKAY]\n[squeezenet_v11_7](test_data_set_1)                                                     [OKAY]\n[squeezenet_v11_7](test_data_set_2)                                                     [OKAY]\n[super_resolution_10](test_data_set_0)                                                  [OKAY]\n[tinyyolo_v2_8](test_data_set_0)                                                        [OKAY]\n[tinyyolo_v2_8](test_data_set_1)                                                        [OKAY]\n[tinyyolo_v2_8](test_data_set_2)                                                        [OKAY]\n```\n\nNote 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.\n\n## Notes\n\n- This library based on the onnx version [v1.17.0](https://github.com/onnx/onnx/tree/v1.17.0) with the newest `opset 23` support. [The supported operator table](documents/the-supported-operator-table.md) in the [documents](documents) directory.\n- Checkout the `tools` folder for help with ONNX model files.\n- You can use `xxd -i \u003cfilename.onnx\u003e` (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`.\n\n## Links\n\n* [The chinese discussion posts](https://whycan.com/t_5440.html)\n* [The onnx operators documentation](https://github.com/onnx/onnx/blob/master/docs/Operators.md)\n* [The tutorials for creating ONNX models](https://github.com/onnx/tutorials)\n* [The pre-trained onnx models](https://github.com/onnx/models)\n\n## License\n\nThis library is free software; you can redistribute it and or modify it under the terms of the MIT license. See [MIT License](LICENSE) for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxboot%2Flibonnx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxboot%2Flibonnx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxboot%2Flibonnx/lists"}