onnx-go: github.com/owulveryck/onnx-go Index | Examples | Files | Directories

package onnx

import "github.com/owulveryck/onnx-go"

Code:

package main

import (
    "fmt"
    "io/ioutil"
    "log"

    "github.com/owulveryck/onnx-go"
    "github.com/owulveryck/onnx-go/backend/x/gorgonnx"
    "gorgonia.org/tensor"
)

var input tensor.Tensor

func main() {
    // Create a backend receiver
    backend := gorgonnx.NewGraph()
    // Create a model and set the execution backend
    model := onnx.NewModel(backend)

    // read the onnx model
    b, _ := ioutil.ReadFile("model.onnx")
    // Decode it into the model
    err := model.UnmarshalBinary(b)
    if err != nil {
        log.Fatal(err)
    }
    // Set the first input, the number depends of the model
    model.SetInput(0, input)
    err = backend.Run()
    if err != nil {
        log.Fatal(err)
    }
    // Check error
    output, _ := model.GetOutputTensors()
    // write the first output to stdout
    fmt.Println(output[0])
}

Code:

// START SIMPLE
// Create a backend receiver
backend := simple.NewSimpleGraph()
// Create a model and set the execution backend
model := onnx.NewModel(backend)

// read the onnx model
b, _ := ioutil.ReadFile("model.onnx")
// Decode it into the model
err := model.UnmarshalBinary(b)
// END SIMPLE
if err != nil {
    log.Fatal(err)
}

Index

Examples

Package Files

attributes.go backend.go decoder.go errors.go io.go node.go tensor.go

func NewTensor Uses

func NewTensor(b []byte) (tensor.Tensor, error)

NewTensor from onnx value

type Backend Uses

type Backend interface {
    OperationCarrier
    graph.DirectedWeightedBuilder
}

Backend represent any backend able to receive a computation graph

type DataCarrier Uses

type DataCarrier interface {
    SetTensor(t tensor.Tensor) error
    GetTensor() tensor.Tensor
}

DataCarrier is node with the ability to carry a tensor data

type Documenter Uses

type Documenter interface {
    graph.Node
    SetDescription(string)
    GetDescription() string
}

Documenter is an interface that describe any object able to document itself

type ErrNotImplemented Uses

type ErrNotImplemented struct {
    Operator       string
    AttributeName  string
    AttributeValue interface{}
    Message        string
}

ErrNotImplemented is returned for any operator or attribute

func (*ErrNotImplemented) Error Uses

func (e *ErrNotImplemented) Error() string

type InvalidUnmarshalError Uses

type InvalidUnmarshalError struct {
    Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error Uses

func (e *InvalidUnmarshalError) Error() string

type Model Uses

type Model struct {
    Input  []int64
    Output []int64
    // contains filtered or unexported fields
}

Model is a wrapper around a computation graph. Input and Output are containing the ID of the corresponding nodes.

func NewModel Uses

func NewModel(dst Backend) *Model

NewModel with dst as backend. dst should be a non-nil pointer.

func (*Model) GetInputTensors Uses

func (m *Model) GetInputTensors() []tensor.Tensor

GetInpuTensors from the graph. This function is useful to get informations if the tensor is a placeholder and does not contain any data yet.

func (*Model) GetNodeByName Uses

func (m *Model) GetNodeByName(name string) (graph.Node, bool)

GetNodeByName is a utility method that returns a node of the computation graph

func (*Model) GetOutputTensors Uses

func (m *Model) GetOutputTensors() ([]tensor.Tensor, error)

GetOutputTensors of the graph

func (*Model) SetInput Uses

func (m *Model) SetInput(i int, t tensor.Tensor) error

SetInput assign a tensor to the i-th input of the graph

func (*Model) UnmarshalBinary Uses

func (m *Model) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the binary data in onnx format into the model

type Namer Uses

type Namer interface {
    graph.Node
    SetName(string)
    GetName() string
}

Namer is a node that know its own name

type Operation Uses

type Operation struct {
    Name       string
    Attributes map[string]interface{}
}

Operation defined by its name and its attribute

type OperationCarrier Uses

type OperationCarrier interface {
    // ApplyOperation on the graph nodes
    // graph.Node is an array because it allows to handle multiple output
    // for example a split operation returns n nodes...
    ApplyOperation(Operation, ...graph.Node) error
}

OperationCarrier should be a method of the graph because the operation needs the topology of the graph to check the arity of the node for example

Directories

PathSynopsis
backend
backend/simplePackage simple holds a very simple graph structure suitable to receive an onnx model
backend/testbackendPackage testbackend provides a set of testing helper functions that test backend interface implementations.
backend/testbackend/onnx
backend/testbackend/onnx/gen_cmd
backend/testbackend/testreport
backend/x/gorgonnxPackage gorgonnx creates a temporary graph that is compatible with backend.ComputationBackend.
backend/x/gorgonnx/genapi
internal/examples/mnist
internal/examples/mnist/gen
internal/onnx/ir
internal/readme
internal/x/images

Package onnx imports 7 packages (graph) and is imported by 8 packages. Updated 2020-01-01. Refresh now. Tools for package owners.