mirror of
https://github.com/yalue/onnxruntime_go.git
synced 2025-09-27 11:42:24 +08:00

- Sets up the onnxruntime environment, but doesn't load or run networks yet. - The things builds and run on Windows. - Still working on getting the Linux (arm64 for now) test to work.
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// This application loads a test ONNX network and executes it on some fixed
|
|
// data. It serves as an example of how to use the onnxruntime wrapper library.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/yalue/onnxruntime"
|
|
"os"
|
|
"runtime"
|
|
)
|
|
|
|
func run() int {
|
|
if runtime.GOOS == "windows" {
|
|
onnxruntime.SetSharedLibraryPath("../test_data/onnxruntime.dll")
|
|
} else {
|
|
onnxruntime.SetSharedLibraryPath("../test_data/onnxruntime.so")
|
|
}
|
|
e := onnxruntime.InitializeEnvironment()
|
|
if e != nil {
|
|
fmt.Printf("Error initializing the onnxruntime environment: %s\n", e)
|
|
return 1
|
|
}
|
|
fmt.Printf("The onnxruntime environment initialized OK.\n")
|
|
|
|
// Ordinarily, it is probably fine to call this using defer, but we do it
|
|
// here just so we can print a status message after the cleanup completes.
|
|
e = onnxruntime.CleanupEnvironment()
|
|
if e != nil {
|
|
fmt.Printf("Error cleaning up the environment: %s\n", e)
|
|
return 1
|
|
}
|
|
fmt.Printf("The onnxruntime environment was cleaned up OK.\n")
|
|
return 0
|
|
}
|
|
|
|
func main() {
|
|
os.Exit(run())
|
|
}
|