operators

package
v0.0.0-...-db9b1aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Operators

This directory holds the operators that can be promoted and used in gorgonnx. All the operators fulfils the Operator interface{}

Add a new operator

If you want to add an operator, be sure to read its documentation from the ONNX web page.

Then generate a skeleton of implementation and the unit tests with

./op.sh operator # operator is lowercase

This will generate two files:

  • operator_autogenerated_tests.go
  • operator_todo.go

Tests

The file operator_autogenerated_tests.go is a pure go representation of the onnx tests related to the operator. if you run

go test -run=Operator

you should see that all the tests are skipped because by default the Init and Apply methods return an ErrNotImplemented error.

Implementation

a good practise is to rename the file from _todo.go to _wip.go until the implementation is ok.

Init

You should start by implementing the Init method. You can rely on the UnmarshalAttributes method of the onnx-go package.

Read the onnx documentation of the package and create an inner-type that will hold the values.

For example, if Operator expects an attribute named myattribute of type int with a defaut value of 42, just create

type attributes struct {
    MyAttr int64 `attributeName:"myattribute"`
}
// Create an instance with default values
attr := attributes{
      MyAttr: 42,
}
err := onnx.UnmarshalAttributes(attrs, &attr)
Apply

The apply method is straightforward. See the Add Operator for an example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Add

type Add struct {
	// contains filtered or unexported fields
}

Add operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Add Warning this operation is broadcastable See https://github.com/onnx/onnx/blob/master/docs/Broadcasting.md

func (*Add) Apply

func (a *Add) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply the operator; broadcasting is evaluated and applied if needed

func (*Add) Init

func (a *Add) Init(attrs []*onnx.AttributeProto) error

Init is a noop as Add do not have any attribute

type Batchnorm

type Batchnorm struct {
	Epsilon  float64
	Momentum float64
	Spatial  int
	// contains filtered or unexported fields
}

Batchnorm operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#BatchNormalization

func (*Batchnorm) Apply

func (o *Batchnorm) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Batchnorm) Init

func (o *Batchnorm) Init(attrs []*onnx.AttributeProto) error

Init ...

type Concat

type Concat struct {
	Axis int
	// contains filtered or unexported fields
}

Concat operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Concat

func (*Concat) Apply

func (o *Concat) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Concat) Init

func (o *Concat) Init(attrs []*onnx.AttributeProto) error

Init ...

type Constant

type Constant struct {
	Tensor tensor.Tensor
	// contains filtered or unexported fields
}

Constant operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Constant

func (*Constant) Apply

func (o *Constant) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Constant) Init

func (o *Constant) Init(attrs []*onnx.AttributeProto) error

Init ...

type Conv

type Conv struct {
	AutoPad     string
	Pads        []int
	Dilations   []int
	Group       int
	KernelShape tensor.Shape
	Strides     []int
	// contains filtered or unexported fields
}

Conv operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Conv

For more information about convolution, please visit https://github.com/vdumoulin/conv_arithmetic/blob/master/README.md

func (*Conv) Apply

func (c *Conv) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Conv) Init

func (c *Conv) Init(attrs []*onnx.AttributeProto) error

Init the convolution operator

type Div

type Div struct {
	// contains filtered or unexported fields
}

Div operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Div

func (*Div) Apply

func (o *Div) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply the Hadamard Div to the input nodes. Broadcasting is computed and applied if needed

func (*Div) Init

func (o *Div) Init(attrs []*onnx.AttributeProto) error

Init of the operator; the operator does not expect any attribute; therefore, any value of attrs is silently discarded

type Dropout

type Dropout struct {
	// contains filtered or unexported fields
}

Dropout operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Dropout

func (*Dropout) Apply

func (o *Dropout) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Dropout) Init

func (o *Dropout) Init(attrs []*onnx.AttributeProto) error

Init ...

type ErrBadArity

type ErrBadArity struct {
	Operator       string
	ExpectedInput  int
	ActualInput    int
	ExpectedOutput int
	ActualOutput   int
}

ErrBadArity is raised when an operator do not have the correct amount of input or output

func (*ErrBadArity) Error

func (e *ErrBadArity) Error() string

type Matmul

type Matmul struct {
	// contains filtered or unexported fields
}

Matmul operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Matmul

func (*Matmul) Apply

func (o *Matmul) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Matmul) Init

func (o *Matmul) Init(attrs []*onnx.AttributeProto) error

Init ...

type Maxpool

type Maxpool struct {
	Pads         []int
	AutoPad      string
	StorageOrder int
	KernelShape  tensor.Shape
	Strides      []int
	// contains filtered or unexported fields
}

Maxpool operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#MaxPool

func (*Maxpool) Apply

func (o *Maxpool) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Maxpool) Init

func (o *Maxpool) Init(attrs []*onnx.AttributeProto) error

Init ...

type Mul

type Mul struct {
	// contains filtered or unexported fields
}

Mul operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Mul

func (*Mul) Apply

func (o *Mul) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply the Hadamard Product to the input nodes. Broadcasting is computed and applied if needed

func (*Mul) Init

func (o *Mul) Init(attrs []*onnx.AttributeProto) error

Init of the operator; the operator does not expect any attribute; therefore, any value of attrs is silently discarded

type Relu

type Relu struct {
	// contains filtered or unexported fields
}

Relu operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Relu

func (*Relu) Apply

func (o *Relu) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Relu) Init

func (o *Relu) Init(attrs []*onnx.AttributeProto) error

Init ...

type Reshape

type Reshape struct {
	// contains filtered or unexported fields
}

Reshape operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Reshape

func (*Reshape) Apply

func (r *Reshape) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Reshape) Init

func (r *Reshape) Init(attrs []*onnx.AttributeProto) error

Init is a noop as Reshape do not have any attribute

type Unsqueeze

type Unsqueeze struct {
	Axes []int64
	// contains filtered or unexported fields
}

Unsqueeze operator https://github.com/onnx/onnx/blob/master/docs/Operators.md#Unsqueeze

func (*Unsqueeze) Apply

func (o *Unsqueeze) Apply(input ...*gorgonia.Node) ([]*gorgonia.Node, error)

Apply ...

func (*Unsqueeze) Init

func (o *Unsqueeze) Init(attrs []*onnx.AttributeProto) error

Init ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL