-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
example_gorgonnx_test.go
38 lines (33 loc) · 773 Bytes
/
example_gorgonnx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package onnx_test
import (
"fmt"
"log"
"os"
"github.com/owulveryck/onnx-go"
"github.com/owulveryck/onnx-go/backend/x/gorgonnx"
"gorgonia.org/tensor"
)
var input tensor.Tensor
func Example_gorgonia() {
// Create a backend receiver
backend := gorgonnx.NewGraph()
// Create a model and set the execution backend
model := onnx.NewModel(backend)
// read the onnx model
b, _ := os.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])
}