Documentation ¶
Overview ¶
Package gorgonnx creates a temporary graph that is compatible with backend.ComputationBackend.
Example (FizzBuzz) ¶
package main import ( "fmt" "log" "github.com/godshen/onnx-go" "gorgonia.org/tensor" ) func bin(n int, numDigits int) []float32 { f := make([]float32, numDigits) for i := uint(0); i < uint(numDigits); i++ { f[i] = float32((n >> i) & 1) } return f[:] } func dec(b []float32) int { for i := 0; i < len(b); i++ { if b[i] > 0.4 { return i } } panic("Sorry, I'm wrong") } func display(v []float32, i int) { switch dec(v) { case 0: fmt.Println(i) case 1: fmt.Println("Fizz") case 2: fmt.Println("Buzz") case 3: fmt.Println("FizzBuzz") } } func main() { backend := NewGraph() m := onnx.NewModel(backend) err := m.UnmarshalBinary(fizzBuzzOnnx) if err != nil { log.Fatal(err) } input := tensor.New(tensor.WithShape(7), tensor.Of(tensor.Float32)) for i := 1; i <= 100; i++ { for j, v := range bin(i, 7) { input.SetAt(v, j) } m.SetInput(0, input) err = backend.Run() if err != nil { log.Fatal(err) } output, err := m.GetOutputTensors() if err != nil { log.Fatal(err) } display(output[0].Data().([]float32), i) } }
Output: 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52 53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86 Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz
Index ¶
- func ExampleOperator()
- type Graph
- func (g *Graph) AddNode(n graph.Node)
- func (g *Graph) ApplyOperation(o onnx.Operation, ns ...graph.Node) error
- func (g *Graph) Edge(uid, vid int64) graph.Edge
- func (g *Graph) From(id int64) graph.Nodes
- func (g *Graph) GetExprGraph() (*gorgonia.ExprGraph, error)
- func (g *Graph) HasEdgeBetween(xid, yid int64) bool
- func (g *Graph) HasEdgeFromTo(uid, vid int64) bool
- func (g *Graph) NewNode() graph.Node
- func (g *Graph) NewWeightedEdge(from, to graph.Node, w float64) graph.WeightedEdge
- func (g *Graph) Node(id int64) graph.Node
- func (g *Graph) Nodes() graph.Nodes
- func (g *Graph) PopulateExprgraph() error
- func (g *Graph) Run() error
- func (g *Graph) SetWeightedEdge(e graph.WeightedEdge)
- func (g *Graph) To(id int64) graph.Nodes
- type Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is the top structure that should be compatible with
backend.ComputationGraph
It holds a gorgonia.ExprGraph that is populated on the first call to the Run() method
func (*Graph) ApplyOperation ¶
ApplyOperation to fulfill the onnx.Backend interface
func (*Graph) GetExprGraph ¶
GetExprGraph returns the gorgonia graph; if the graph is nil, it populates the graph before returing it
func (*Graph) HasEdgeBetween ¶
HasEdgeBetween ...
func (*Graph) NewWeightedEdge ¶
NewWeightedEdge returns a new WeightedEdge from the source to the destination node. Fulfills the graph.WeightedEdgeAdder interface
func (*Graph) PopulateExprgraph ¶
PopulateExprgraph creates the underlynig graph by walking the current graph
func (*Graph) SetWeightedEdge ¶
func (g *Graph) SetWeightedEdge(e graph.WeightedEdge)
SetWeightedEdge adds an edge from one node to another. If the graph supports node addition the nodes will be added if they do not exist, otherwise SetWeightedEdge will panic. The behavior of a WeightedEdgeAdder when the IDs returned by e.From() and e.To() are equal is implementation-dependent. Whether e, e.From() and e.To() are stored. Fulfills the graph.WeightedEdgeAdder interface
Source Files ¶
- apigen_operators.go
- batchnorm.go
- batchnorm_op.go
- broadcast.go
- concat.go
- constant.go
- conv.go
- div_integer.go
- doc.go
- dropout.go
- errors.go
- example_operator.go
- flatten.go
- gap.go
- gather_operator.go
- gemm.go
- graph.go
- graph_walk.go
- identity.go
- image_scaler.go
- leakyrelu.go
- matmul.go
- maxpool.go
- min_max.go
- node.go
- operator.go
- reshape.go
- shape.go
- softmax.go
- sort.go
- squeeze.go
- transpose.go
- uniq.go
- unsqueeze.go
- weighted_graph_builder.go