Skip to content

knights-analytics/gonnx

 
 

Repository files navigation

GONNX

image info

License: MPL 2.0

The goal of this package is to provide an easy way of running ONNX models in Go. This package is intended for inference usage of ONNX models. The package can be used to load an .onnx file and perform inference using the model described by this file.

Currently, we are implementing ONNX operation set 13, and we plan to add all opsets following this one as well. Feel free to contribute by implementing operators!

Getting started

Installation & setup

First, install Go on your machine. Then, clone the repository:

git clone https://github.com/AdvancedClimateSystems/gonnx.git
cd gonnx

Then, install the dependencies as follows:

make install
make install_lint
make install_gotestsum

Usage

A simple example is shown below:

package main

import (
    "github.com/advancedclimatesystems/gonnx"
    "gorgonia.org/tensor"
)


func main() {
    model, err := gonnx.NewModel("./path_to_onnx/model.onnx")
    if err != nil {
        log.Fatal(err)
    }

    var inputs map[string]*tensor.Tensor
    inputs = // However you construct inputs. It must have a tensor for all inputs.

    result, err := model.Run(inputs)
    if err != nil {
        log.Fatal(err)
    }
}

Tests

Most of the code should be tested. If you add operators (or an entire opset version) make sure you add unit tests as wel as tests for the ONNX test suite

The GONNX test suite consists of unit tests and integration tests, the standard provided by ONNX.

The ONNX test data is not stored in the repository, hence one needs to download it first:

make test_data

Now, one can run all tests using (which runs both integration and unit tests):

make test

Because the current implementation is lacking certain opset versions, some of the tests from ONNX will not run. All tests that are skipped can be found in ops_test.go, as well as the reason that particular test is skipped. We try to be explicit in which tests are ran and which are skipped.

How to Contribute

Any kind of contribution is welcome. Try to keep the style consistent and make sure all linter checks succeed before opening a pull request.

Pull requests

Our workflow is based on the github-flow .

  1. Create a new issue.

  2. Fork the project.

  3. Clone your fork and add the upstream.

    git remote add upstream https://github.com/AdvancedClimateSystems/gonnx.git
  4. Pull new changes from the upstream.

    git checkout main
    git fetch upstream
    git merge upstream/main
  5. Create a feature branch

    git checkout -b <branch-name>
  6. Commit your changes and reference the issue number in your comment.

    git commit -m "Issue #<issue-ref> : <your message>"
  7. Push the feature branch to your remote repository.

    git push origin <branch-name>
  8. Open new pull request.

Code of conduct

Welcome to the GONNX community! To make sure everyone has a blast while working together, here's our quick code of conduct:

  1. Be respectful and kind to everyone. No hate speech or harassment allowed.
  2. Keep conversations on topic and respectful.
  3. Respect other people's work and intellectual property rights.
  4. Follow the guidelines for contributing to the project and make your first pull request! Anything is welcome 🙂
  5. If you see something, say something. Report any violations to the maintainers.
  6. Have fun! We're all here to work on something awesome together, so let's make the most of it!

By participating in the GONNX project, you're agreeing to follow these guidelines and make sure everyone has a good time. Whether you're a seasoned veteran or a newcomer, we're excited to have you here. Let's make something amazing!

Authors

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.2%
  • Python 1.3%
  • Makefile 0.5%