c3sr / go-onnxruntime

26 stars 8 forks source link

Failed to create simple model on cpu #5

Open magicaltoast opened 2 years ago

magicaltoast commented 2 years ago

I'm trying to do inference with model generated with Keras and saved to onnx format. But I'm getting an error while creating the model. Code was based on provided example

Error

go run -tags='nogpu' main.go 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xcd36ff]

goroutine 1 [running]:
main.main()
        /home/idk/golang_onnx/main.go:27 +0x1ff
exit status 2
(base) idk@idk:~

Code

package main

import (
    "context"
    "fmt"
    "path/filepath"

    "github.com/c3sr/dlframework/framework/options"
    "github.com/c3sr/go-onnxruntime"
    "github.com/c3sr/tracer"
)

func main() {
    device := options.CPU_DEVICE
    graph := filepath.Join("/home/idk/golang_onnx", "model.onnx")

    ctx := context.Background()
    opts := options.New(options.Context(ctx),
        options.Graph([]byte(graph)),
        options.Device(device, 0),
        options.BatchSize(9))

    opts.SetTraceLevel(tracer.FULL_TRACE)

    span, ctx := tracer.StartSpanFromContext(ctx, tracer.FULL_TRACE, "onnxruntime_batch")
    defer span.Finish()

    predictor, err := onnxruntime.New(
        ctx,
        options.WithOptions(opts),
    )
    defer predictor.Close()
    fmt.Println(err)
}