onnx

package module
v0.0.0-...-85e929e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2021 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Introduction

Go binding for onnx runtime, only support 1 input and 1 output in current phase

Build

  • export CGO_CFLAGS=-I/source/onnxruntime-osx/include
  • export CGO_LDFLAGS=-L/source/onnxruntime-osx/lib

Example

package main

import (
	"github.com/carck/onnx-runtime-go"
	"log"
)

func main() {
	shape := []int64{1, 3, 112, 112}
	inputNames := []string{"input.1"}
	outputNames := []string{"683"}
	model := onnx.NewModel("facenet.onnx", shape, inputNames, outputNames, onnx.CPU)
	defer model.Delete()

	data := make([]float32, 1*3*112*112)
	output := model.RunInference(data)
	defer output.Delete()

	log.Println("num dims: %s", output.NumDims())
	log.Println("dim1: %s", output.Dim(1))
	
	res := make([]float32, 512)
	output.CopyToBuffer(res, 512*4)
	fmt.Printf("%v", res)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EuclideanDistance512 = func(a, b []float32) float32 {
	var (
		s, t float32
	)

	for i := 0; i < 512; i++ {
		t = a[i] - b[i]
		s += t * t
	}

	return float32(math.Sqrt(float64(s)))
}
View Source
var EuclideanDistance512C = func(a, b []float32) float32 {
	res := C.EuclideanDistance512((*C.float)(unsafe.Pointer(&a[0])), (*C.float)(unsafe.Pointer(&b[0])))
	return float32(res)
}

Functions

This section is empty.

Types

type EP

type EP int
const (
	CPU EP = iota
	CUDA
	ROCM
	ARMNN
	TENSORRT
)

type Model

type Model struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel(model_path string, shape []int64, inputNames []string, outputNames []string, mode EP) *Model

func (*Model) Delete

func (m *Model) Delete()

func (*Model) RunInference

func (m *Model) RunInference(data []float32) *Tensor

Invoke invoke the task.

type Tensor

type Tensor struct {
	// contains filtered or unexported fields
}

func (*Tensor) CopyToBuffer

func (t *Tensor) CopyToBuffer(b interface{}, size int)

func (*Tensor) Delete

func (t *Tensor) Delete()

func (*Tensor) Dim

func (t *Tensor) Dim(index int) int64

Dim return dimension of the element specified by index.

func (*Tensor) NumDims

func (t *Tensor) NumDims() int

func (*Tensor) Shape

func (t *Tensor) Shape() []int64

Shape return shape of the tensor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL