1 Star 0 Fork 1

wb253 / onnxruntime

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

onnxruntime Wrapper for Go

关于

该库提供golang 运行机器学习模型,由于是通过调用C 和 C++ API来运行,因此需要支持 cgo。 如果要使用 CUDA,则需要使用支持 CUDA 的 onnxruntime 共享库,以及使用 CUDA OnnxRuntime 库的基础版本支持的版本。CUDA 支持文档

onnxruntime 版本问题

当前这个库使用的是onnxruntime 1.16.3版本,如果需要使用其他版本,需要修改代码。

  1. 替换新版本 onnxruntime_c_api.h;

  2. 指定新版本的 libonnxruntime.dll (or libonnxruntime.so)

C API header 和 动态库文件 official repo. 在这里可以下载最新的onnxruntime库. 如果你想要在windows 上支持GPU,还需要execution_providers_cuda.dllexecution_providers_shared.dll

使用示例

import (
	"fmt"
	ort "gitee.com/wb253/onnxruntime"
)

func main() {
	ort.SetSharedLibraryPath("/usr/local/lib/libonnxruntime.so")
	ort.InitializeEnvironment()
	defer ort.DestroyEnvironment()

	inputData := []float32{0.19473445415496826, 0.9139836430549622, 0.7043011784553528, 0.7685686945915222}
	inputShape := ort.NewShape(1, 1, 4)
	inputTensor, _ := ort.NewTensor(inputShape, inputData)
	defer inputTensor.Destroy()
	// This hypothetical network maps a 2x5 input -> 2x3x4 output.
	outputShape := ort.NewShape(1, 1, 2)
	outputTensor, _ := ort.NewEmptyTensor[float32](outputShape)
	defer outputTensor.Destroy()
	session, _ := ort.NewSession("./example_network.onnx",
		[]string{"1x4 Input Vector"}, []string{"1x2 Output Vector"}, nil)
	defer session.Destroy()
	// Calling Run() will run the network, reading the current contents of the
	// input tensors and modifying the contents of the output tensors.
	err := session.Predict([]ort.ArbitraryTensor{inputTensor}, []ort.ArbitraryTensor{outputTensor})

	if err != nil {
		fmt.Printf("err %s", err)
		return
	}
	fmt.Printf("output: %+v\r\n", outputTensor.GetData())
}

空文件

简介

golang onnxruntime 展开 收起
C++ 等 3 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/wb253/onnxruntime.git
git@gitee.com:wb253/onnxruntime.git
wb253
onnxruntime
onnxruntime
main

搜索帮助