menoh

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: MIT Imports: 4 Imported by: 0

README

Menoh Go

Build Status Build status codecov GoDoc Go Report Card

Golang binding for Menoh

Requirements

Install

After install Menoh, then

$ go get -u github.com/pfnet-research/go-menoh
Linux/Mac

Add a path to library to LD_LIBRARY_PATH environment variable. Menoh libraries are installed to /usr/local/lib on default.

$ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
Windows

Add a path to DLLs distributed by Menoh to local Path environment.

\path\to\menoh\bin
  |- libiomp5md.dll
  |- menoh.dll
  |- mkldnn.dll
  |- mklml.dll
set PATH=\path\to\menoh\bin;%PATH%

Usage

Development

Test

Download ONNX file, using in menoh-rust test, before testing.

$ wget https://github.com/pfnet-research/menoh-rs/releases/download/assets/MLP.onnx -P test_data
$ go test ./...

Additionally go-menoh follows gofmt with simplify option (-s), go vet and golint.

Note

License

MIT License (see LICENSE file).

Documentation

Overview

Package menoh provides a wrapper "runner" for Menoh library to execute ONNX model. It consits the following structures.

Runner is a wrapper to manage an ONNX model and run with input variables.

Config is information about ONNX model, required for making a runner.

Tensor represents number array for in/out variable, similar to ONNX's Tensor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ONNXModelPath string         // path of ONNX file
	Backend       TypeBackend    // backend type, like menoh.TypeMKLDNN
	BackendConfig string         // backend configuration
	Inputs        []InputConfig  // list of input configuration
	Outputs       []OutputConfig // list of output configuration
}

Config is setup information to build Menoh model.

type FloatTensor

type FloatTensor struct {
	Dims  []int32
	Array []float32
}

FloatTensor represents float32 Tessor.

func (*FloatTensor) FloatArray

func (t *FloatTensor) FloatArray() ([]float32, error)

FloatArray returns float32 array.

func (*FloatTensor) Shape

func (t *FloatTensor) Shape() []int32

Shape returns shape of array.

func (*FloatTensor) Size

func (t *FloatTensor) Size() int

Size returns array size.

func (*FloatTensor) WriteFloat

func (t *FloatTensor) WriteFloat(i int, f float32) error

WriteFloat puts float value to i-th index of array.

type InputConfig

type InputConfig struct {
	Name  string    // layer name
	Dtype TypeDtype // data type
	Dims  []int32   // list of dimension size
}

InputConfig is input variable information to pass to the model.

type ModelData added in v0.2.0

type ModelData struct {
	external.ModelData
}

ModelData is a wrap of menoh.ModelData.

func NewModelDataFromBytes added in v0.2.0

func NewModelDataFromBytes(data []byte) (*ModelData, error)

NewModelDataFromBytes return ModelData from binary data.

func NewModelDataFromPath added in v0.2.0

func NewModelDataFromPath(path string) (*ModelData, error)

NewModelDataFromPath returns ModelData using ONNX file placed on the path.

func NewRawModelData added in v0.2.0

func NewRawModelData() (*ModelData, error)

NewRawModelData return empty ModelData to be setup outer.

func (*ModelData) AddTensorParameter added in v0.2.0

func (m *ModelData) AddTensorParameter(name string, param Tensor) error

AddTensorParameter adds tensor to named parameter.

type OutputConfig

type OutputConfig struct {
	Name         string    // layer name
	Dtype        TypeDtype // data type
	FromInternal bool      // if the output comes from operator variable such as weight, set true
}

OutputConfig is output variable information to get from the model.

type Runner

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

Runner setups Menoh model with profiling and executes with input variables. A runner supports to call Run (or RunWithTensor) method repeatedly until stopping.

func NewRunner

func NewRunner(conf Config) (*Runner, error)

NewRunner returns Runner using configuration, the runner setup Menoh model and ready for execution. Require to call Stop function after the process is done.

func NewRunnerWithModelData added in v0.2.0

func NewRunnerWithModelData(modelData *ModelData, conf Config) (*Runner, error)

NewRunnerWithModelData returns Runner using configuration and ONNX model. The ONNX model is passed on memory, not use conf.ONNXModelPath. Spec of a returned runner is same as NewRunner, see docs of the function.

func (*Runner) GetInput

func (r *Runner) GetInput(name string) (Tensor, error)

GetInput returns a Tensor attached to the target model.

func (*Runner) GetOutput

func (r *Runner) GetOutput(name string) (Tensor, error)

GetOutput returns the target variable.

func (*Runner) Outputs

func (r *Runner) Outputs() map[string]Tensor

Outputs all variables set by the configuration.

func (*Runner) Run

func (r *Runner) Run(inputs map[string]Tensor) error

Run with the inputs which are set name and tensor as key-value. If nothing to input, set nil.

func (*Runner) RunWithTensor

func (r *Runner) RunWithTensor(name string, t Tensor) error

RunWithTensor inputs the tenser with tne name, and runs.

func (*Runner) Stop

func (r *Runner) Stop()

Stop the runner.

type Tensor

type Tensor interface {

	// Size returns array size.
	Size() int

	// Shape returns shape of array dimension.
	Shape() []int32

	// FloatArray returns float32 array. Returns an error when the array
	// cannot cast to the type. It is possible that returned array is copied
	// or split-off from attached array in Menoh model. When updating values,
	// WriteFloat method.
	FloatArray() ([]float32, error)

	// WriteFloat puts float value to i-th index of array.
	WriteFloat(int, float32) error
	// contains filtered or unexported methods
}

Tensor is base unit of matrix data to pass Menoh model.

type TypeBackend

type TypeBackend int

TypeBackend is a type of backend, like MKL-DNN.

const (

	// TypeMKLDNN is a TypeBackend of MKL-DNN
	TypeMKLDNN TypeBackend
)

func (TypeBackend) String

func (t TypeBackend) String() string

type TypeDtype

type TypeDtype int

TypeDtype is a type of data.

const (

	// TypeFloat is a TypeDtype of Float.
	TypeFloat TypeDtype
)

Directories

Path Synopsis
example
Package external provides APIs to operate Menoh model directory.
Package external provides APIs to operate Menoh model directory.
tools
onnx
Package onnx is a generated protocol buffer package.
Package onnx is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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