{"id":13413374,"url":"https://github.com/oramasearch/onnx-go","last_synced_at":"2025-05-16T13:05:46.658Z","repository":{"id":33287492,"uuid":"146410333","full_name":"oramasearch/onnx-go","owner":"oramasearch","description":"onnx-go gives the ability to import a pre-trained neural network within Go without being linked to a framework or library.","archived":false,"fork":false,"pushed_at":"2024-09-02T01:46:08.000Z","size":52119,"stargazers_count":774,"open_issues_count":44,"forks_count":75,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-16T13:05:42.734Z","etag":null,"topics":["go","gorgonia","machine-learning","neural-network","onnx","open-source","protobuf","software2"],"latest_commit_sha":null,"homepage":"https://blog.owulveryck.info/2019/04/03/from-a-project-to-a-product-the-state-of-onnx-go.html","language":"Go","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/oramasearch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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},"funding":{"github":["owulveryck"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-08-28T07:39:20.000Z","updated_at":"2025-05-12T02:10:58.000Z","dependencies_parsed_at":"2024-06-18T13:58:37.572Z","dependency_job_id":"2589bc87-8fec-486b-8d1f-19454e4838e4","html_url":"https://github.com/oramasearch/onnx-go","commit_stats":null,"previous_names":["askorama/onnx-go","oramasearch/onnx-go"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Fonnx-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Fonnx-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Fonnx-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oramasearch%2Fonnx-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oramasearch","download_url":"https://codeload.github.com/oramasearch/onnx-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535827,"owners_count":22087399,"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":["go","gorgonia","machine-learning","neural-network","onnx","open-source","protobuf","software2"],"created_at":"2024-07-30T20:01:38.873Z","updated_at":"2025-05-16T13:05:46.605Z","avatar_url":"https://github.com/oramasearch.png","language":"Go","funding_links":["https://github.com/sponsors/owulveryck"],"categories":["Machine Learning"],"sub_categories":["Search and Analytic Databases","Advanced Console UIs"],"readme":"![ONNX Logo](vignettes/imgs/ONNX_logo_main.png) ![Go Logo](vignettes/imgs/Go-Logo_Blue.png)\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#machine-learning) [![GoDoc](https://godoc.org/github.com/owulveryck/onnx-go?status.svg)](https://godoc.org/github.com/owulveryck/onnx-go) [![Go Report Card](https://goreportcard.com/badge/github.com/owulveryck/onnx-go)](https://goreportcard.com/report/github.com/owulveryck/onnx-go)\n[![Build Status](https://travis-ci.com/owulveryck/onnx-go.svg?branch=master)](https://travis-ci.com/owulveryck/onnx-go)\n[![CodeCov](https://codecov.io/gh/owulveryck/onnx-go/branch/master/graph/badge.svg)](https://codecov.io/gh/owulveryck/onnx-go)\n\nThis is a Go Interface to [Open Neural Network Exchange (ONNX)](https://onnx.ai/).\n\n# READ BEFORE USING\n\nThis project was originally created by [owulveryck](https://github.com/owulveryck), and archived on May 31, 2024.\n\nAt [Orama](https://orama.com), we decided to revive the project and we'll be dedicating some substantial efforts to make it shine again!\n\nWith that being said, thank you [owulveryck](https://github.com/owulveryck) for your great work and trust in us to bring this project on.\n\nWe're starting now to actively maintain it, so if you find any issues, please be patient.\n\nThanks for your understanding!\n\n## Overview \nonnx-go contains primitives to decode a onnx binary model into a computation backend, and use it like any other library in your go code.\nfor more information about onnx, please visit [onnx.ai](https://onnx.ai).\n\nThe implementation of the [the spec of ONNX](https://github.com/onnx/onnx/blob/master/docs/IR.md) is partial on the import, and non-existent for the export.\n\n### Vision statement\n\n\u003e For the Go developer who needs to add a machine learning capability to his/her code, \n\u003e onnx-go is a package that facilitates the use of neural network models (software 2.0) \n\u003e and unlike any other computation library, this package does not require special skills in data-science.\n\n**Warning** The API is experimental and may change.\n\n### Disclaimer\n[embedmd]:# (RELNOTES.md)\n```md\nThis is a new version of the API.\nThe tweaked version of Gorgonia have been removed. It is now compatible with the master branch of Gorgonia.\nSome operators are not yet available though.\n\nA utility has been added in order to run models from the zoo.\ncheck the `examples` subdirectory.\n```\n\n\n## Install\n\nInstall it via go get\n```\ngo get github.com/owulveryck/onnx-go\n```\n\nonnx-go is compatible with [go modules](https://github.com/golang/go/wiki/Modules).\n\n\n## Example\n\nThose examples assumes that you have a pre-trained `model.onnx` file available.\nYou can download pre-trained modles from the [onnx model zoo](https://github.com/onnx/models).\n\n### Very simple example\n\nThis example does nothing but decoding the graph into a simple backend.\nThen you can do whatever you want with the generated graph.\n\n[embedmd]:# (example_test.go /\\/\\/ Create/ /model.UnmarshalBinary.*/)\n```go\n// Create a backend receiver\n\tbackend := simple.NewSimpleGraph()\n\t// Create a model and set the execution backend\n\tmodel := onnx.NewModel(backend)\n\n\t// read the onnx model\n\tb, _ := ioutil.ReadFile(\"model.onnx\")\n\t// Decode it into the model\n\terr := model.UnmarshalBinary(b)\n```\n\n### Simple example to run a pre-trained model\n\nThis example uses [Gorgonia](https://github.com/gorgonia/gorgonia) as a backend. \n\n```go\nimport \"github.com/owulveryck/onnx-go/backend/x/gorgonnx\"\n```\n\nAt the present time, Gorgonia does not implement all the operators of ONNX. Therefore, most of the model from the model zoo will not work.\nThings will go better little by little by adding more operators to the backend.\n\nYou can find a list of tested examples and a coverage [here](https://github.com/owulveryck/onnx-go/blob/master/backend/x/gorgonnx/ONNX_COVERAGE.md).\n\n[embedmd]:# (example_gorgonnx_test.go /func Ex/ /^}/)\n```go\nfunc Example_gorgonia() {\n\t// Create a backend receiver\n\tbackend := gorgonnx.NewGraph()\n\t// Create a model and set the execution backend\n\tmodel := onnx.NewModel(backend)\n\n\t// read the onnx model\n\tb, _ := ioutil.ReadFile(\"model.onnx\")\n\t// Decode it into the model\n\terr := model.UnmarshalBinary(b)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// Set the first input, the number depends of the model\n\tmodel.SetInput(0, input)\n\terr = backend.Run()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\t// Check error\n\toutput, _ := model.GetOutputTensors()\n\t// write the first output to stdout\n\tfmt.Println(output[0])\n}\n```\n\n### Model zoo\n\nIn the `examples` subdirectory, you will find a utility to run a model from the zoo, as well as a sample utility to analyze a picture with [Tiny YOLO v2](https://pjreddie.com/darknet/yolov2/)\n\n## Internal\n\n### ONNX protobuf definition \n\nThe protobuf definition of onnx has is compiled into Go with the classic `protoc` tool. The definition can be found in the `internal` directory.\nThe definition is not exposed to avoid external dependencies to this repo. Indeed, the pb code can change to use a more efficient compiler such\nas `gogo protobuf` and this change should be transparent to the user of this package.\n\n### Execution backend\n\nIn order to execute the neural network, you need a backend able to execute a computation graph (_for more information on computation graphs, please read this [blog post](http://gopherdata.io/post/deeplearning_in_go_part_1/)_\n\nThis picture represents the mechanism:\n\n![Schema](vignettes/imgs/schema.png)\n\nonnx-go do not provide any executable backend, but for a reference, a simple backend that builds an information graph is provided as an example (see the `simple` subpackage).\nGorgonia is the main target backend of ONNX-Go.\n\n#### Backend implementation\n\na backend is basically a Weighted directed graph that can apply on Operation on its nodes. It should fulfill this interface:\n\n[embedmd]:# (backend.go /type Backend/ /}/)\n```go\ntype Backend interface {\n\tOperationCarrier\n\tgraph.DirectedWeightedBuilder\n}\n```\n\n[embedmd]:# (backend.go /type OperationCarrier/ /}/)\n```go\ntype OperationCarrier interface {\n\t// ApplyOperation on the graph nodes\n\t// graph.Node is an array because it allows to handle multiple output\n\t// for example a split operation returns n nodes...\n\tApplyOperation(Operation, ...graph.Node) error\n}\n```\n\nAn Operation is represented by its `name` and a map of attributes. For example the Convolution operator as described in the [spec of onnx](https://github.com/onnx/onnx/blob/master/docs/Operators.md#Conv) will be represented like this:\n\n[embedmd]:# (conv_example_test.go /convOperator/ /}$/)\n```go\nconvOperator := Operation{\n\t\tName: \"Conv\",\n\t\tAttributes: map[string]interface{}{\n\t\t\t\"auto_pad\":  \"NOTSET\",\n\t\t\t\"dilations\": []int64{1, 1},\n\t\t\t\"group\":     1,\n\t\t\t\"pads\":      []int64{1, 1},\n\t\t\t\"strides\":   []int64{1, 1},\n\t\t},\n\t}\n```\n\nBesides, operators, a node can carry a value. Values are described as [`tensor.Tensor`](https://godoc.org/gorgonia.org/tensor#Tensor)\nTo carry data, a *`Node`* of the graph should fulfill this interface:\n\n[embedmd]:# (node.go /type DataCarrier/ /}/)\n```go\ntype DataCarrier interface {\n\tSetTensor(t tensor.Tensor) error\n\tGetTensor() tensor.Tensor\n}\n```\n\n#### Backend testing\n\nonnx-go provides a some utilities to test a backend. Visit the [`testbackend` package](backend/testbackend) for more info.\n\n## Contributing\n\nContributions are welcome. A contribution guide will be eventually written. Meanwhile, you can raise an issue or send a PR.\nYou can also contact me via Twitter or on the gophers' slack (I am @owulveryck on both)\n\nThis project is intended to be a safe, welcoming space for collaboration, and\ncontributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## Author\n\n[Olivier Wulveryck](https://about.me/owulveryck/getstarted)\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foramasearch%2Fonnx-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foramasearch%2Fonnx-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foramasearch%2Fonnx-go/lists"}