tflite

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 10 Imported by: 14 modules, 13 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-tflite

Binder

Go binding for TensorFlow Lite

Try it in your browser

Click Binder to launch a Jupyter notebook with go-tflite preinstalled and train the iris classifier right in the browser, no install needed. The same image is available as ghcr.io/mattn/go-tflite/gophernotes (see docker/gophernotes).

Usage

model := tflite.NewModelFromFile("sin_model.tflite")
if model == nil {
	log.Fatal("cannot load model")
}
defer model.Delete()

options := tflite.NewInterpreterOptions()
defer options.Delete()

interpreter := tflite.NewInterpreter(model, options)
defer interpreter.Delete()

interpreter.AllocateTensors()

v := float64(1.2) * math.Pi / 180.0
input := interpreter.GetInputTensor(0)
input.Float32s()[0] = float32(v)
interpreter.Invoke()
got := float64(interpreter.GetOutputTensor(0).Float32s()[0])

See _example for more examples

Requirements

  • TensorFlow Lite C API (libtensorflowlite_c.so). CI builds and tests against TensorFlow v2.17.1; other recent versions should work as long as the C API is compatible.

Tensorflow Installation

go-tflite links against libtensorflowlite_c.so only, so there is no need to build the full TensorFlow library. There are three ways to get it.

Prebuilt buildkit

Each release ships tflite-buildkit-<tag>-<target>.tar.gz for linux-amd64, linux-arm64, darwin-amd64, darwin-arm64 and windows-amd64-mingw, containing the headers and the TensorFlow Lite C API library.

On Linux and macOS it also contains the XNNPACK delegate libraries. Extract it into /usr/local and you are done:

$ curl -fSL -o /tmp/buildkit.tar.gz https://github.com/mattn/go-tflite/releases/download/v1.0.10/tflite-buildkit-v1.0.10-linux-amd64.tar.gz
$ sudo tar xzf /tmp/buildkit.tar.gz -C /usr/local
$ sudo ldconfig   # Linux only

On Windows it contains libtensorflowlite_c.dll built with cmake and MinGW-w64 gcc, the toolchain cgo drives, with XNNPACK compiled in, plus the libtensorflowlite_c.dll.a to link against. Extract it anywhere and point cgo at it:

> tar xzf tflite-buildkit-v1.0.10-windows-amd64-mingw.tar.gz -C C:\tflite
> set CGO_CFLAGS=-IC:/tflite/include
> set CGO_LDFLAGS=-LC:/tflite/lib
> set PATH=C:\tflite\lib;%PATH%
> go build -tags xnnpack_builtin .

ci/build-buildkit.sh is the script that produces these tarballs, so you can run it yourself for other TensorFlow versions.

Build with bazel
$ cd /source/directory/tensorflow
$ bazel build -c opt //tensorflow/lite/c:tensorflowlite_c

The XNNPACK delegate has no shared library target upstream; see ci/build-buildkit.sh for how to add one.

Build with cmake
$ cmake -S /source/directory/tensorflow/tensorflow/lite/c -B tflite_build
$ cmake --build tflite_build -j

This produces tflite_build/libtensorflowlite_c.so with XNNPACK compiled in. Because there is no separate libtensorflowlite-delegate_xnnpack.so in this case, build programs that use delegates/xnnpack with -tags xnnpack_builtin so that only libtensorflowlite_c is linked.

There is also Makefile.tflite, a plain Makefile that builds libtensorflowlite_c when placed in tensorflow/lite/c; it is not regularly tested.

Environment variables

If the headers and libraries are not installed in a standard location, tell cgo where to find them:

$ export CGO_CFLAGS=-I/source/directory/tensorflow
$ export CGO_LDFLAGS=-L/path/to/tensorflow/libraries
$ export LD_LIBRARY_PATH=/path/to/tensorflow/libraries

Then run go build on some of the examples.

Edge TPU

To be able to compile and use the EdgeTPU delegate, you need to install the libraries from here: https://github.com/google-coral/edgetpu

There is also a deb package here: https://coral.withgoogle.com/docs/accelerator/get-started/#1-install-the-edge-tpu-runtime

The libraries from should be installed in a system wide library path like /usr/local/lib The include files should be installed somewhere that is accesable from your CGO include path

For x86:

cd /tmp && git clone https://github.com/google-coral/edgetpu.git && \
cp edgetpu/libedgetpu/direct/k8/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1.0 && \
ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so.1 && \
ln -rs /usr/local/lib/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so && \
mkdir -p /usr/local/include/libedgetpu && \
cp edgetpu/libedgetpu/edgetpu.h /usr/local/include/edgetpu.h && \
cp edgetpu/libedgetpu/edgetpu_c.h /usr/local/include/edgetpu_c.h && \
rm -Rf edgetpu

Docker build

See https://github.com/mattn/go-mnist-example/

License

MIT

Author

Yasuhiro Matsumoto (a.k.a. mattn)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTypeMismatch is type mismatch.
	ErrTypeMismatch = errors.New("type mismatch")
	// ErrBadTensor is bad tensor.
	ErrBadTensor = errors.New("bad tensor")
)

Functions

func ExtensionApisVersion added in v1.0.8

func ExtensionApisVersion() string

ExtensionApisVersion return version string of the TensorFlow Lite Extension APIs.

func SchemaVersion added in v1.0.8

func SchemaVersion() int

SchemaVersion return the supported version of the TensorFlow Lite model schema.

func Version added in v1.0.8

func Version() string

Version return version string of TensorFlow Lite.

Types

type BuiltinOperator

type BuiltinOperator int
const (
	BuiltinOperator_ADD                          BuiltinOperator = 0
	BuiltinOperator_AVERAGE_POOL_2D              BuiltinOperator = 1
	BuiltinOperator_CONCATENATION                BuiltinOperator = 2
	BuiltinOperator_CONV_2D                      BuiltinOperator = 3
	BuiltinOperator_DEPTHWISE_CONV_2D            BuiltinOperator = 4
	BuiltinOperator_DEQUANTIZE                   BuiltinOperator = 6
	BuiltinOperator_EMBEDDING_LOOKUP             BuiltinOperator = 7
	BuiltinOperator_FLOOR                        BuiltinOperator = 8
	BuiltinOperator_FULLY_CONNECTED              BuiltinOperator = 9
	BuiltinOperator_HASHTABLE_LOOKUP             BuiltinOperator = 10
	BuiltinOperator_L2_NORMALIZATION             BuiltinOperator = 11
	BuiltinOperator_L2_POOL_2D                   BuiltinOperator = 12
	BuiltinOperator_LOCAL_RESPONSE_NORMALIZATION BuiltinOperator = 13
	BuiltinOperator_LOGISTIC                     BuiltinOperator = 14
	BuiltinOperator_LSH_PROJECTION               BuiltinOperator = 15
	BuiltinOperator_LSTM                         BuiltinOperator = 16
	BuiltinOperator_MAX_POOL_2D                  BuiltinOperator = 17
	BuiltinOperator_MUL                          BuiltinOperator = 18
	BuiltinOperator_RELU                         BuiltinOperator = 19
	BuiltinOperator_RELU_N1_TO_1                 BuiltinOperator = 20
	BuiltinOperator_RELU6                        BuiltinOperator = 21
	BuiltinOperator_RESHAPE                      BuiltinOperator = 22
	BuiltinOperator_RESIZE_BILINEAR              BuiltinOperator = 23
	BuiltinOperator_RNN                          BuiltinOperator = 24
	BuiltinOperator_SOFTMAX                      BuiltinOperator = 25
	BuiltinOperator_SPACE_TO_DEPTH               BuiltinOperator = 26
	BuiltinOperator_SVDF                         BuiltinOperator = 27
	BuiltinOperator_TANH                         BuiltinOperator = 28
	BuiltinOperator_CONCAT_EMBEDDINGS            BuiltinOperator = 29
	BuiltinOperator_SKIP_GRAM                    BuiltinOperator = 30
	BuiltinOperator_CALL                         BuiltinOperator = 31
	BuiltinOperator_CUSTOM                       BuiltinOperator = 32
	BuiltinOperator_EMBEDDING_LOOKUP_SPARSE      BuiltinOperator = 33
	BuiltinOperator_PAD                          BuiltinOperator = 34
	BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_RNN  BuiltinOperator = 35
	BuiltinOperator_GATHER                       BuiltinOperator = 36
	BuiltinOperator_BATCH_TO_SPACE_ND            BuiltinOperator = 37
	BuiltinOperator_SPACE_TO_BATCH_ND            BuiltinOperator = 38
	BuiltinOperator_TRANSPOSE                    BuiltinOperator = 39
	BuiltinOperator_MEAN                         BuiltinOperator = 40
	BuiltinOperator_SUB                          BuiltinOperator = 41
	BuiltinOperator_DIV                          BuiltinOperator = 42
	BuiltinOperator_SQUEEZE                      BuiltinOperator = 43
	BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM BuiltinOperator = 44
	BuiltinOperator_STRIDED_SLICE                BuiltinOperator = 45
	BuiltinOperator_BIDIRECTIONAL_SEQUENCE_RNN   BuiltinOperator = 46
	BuiltinOperator_EXP                          BuiltinOperator = 47
	BuiltinOperator_TOPK_V2                      BuiltinOperator = 48
	BuiltinOperator_SPLIT                        BuiltinOperator = 49
	BuiltinOperator_LOG_SOFTMAX                  BuiltinOperator = 50
	BuiltinOperator_DELEGATE                     BuiltinOperator = 51
	BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM  BuiltinOperator = 52
	BuiltinOperator_CAST                         BuiltinOperator = 53
	BuiltinOperator_PRELU                        BuiltinOperator = 54
	BuiltinOperator_MAXIMUM                      BuiltinOperator = 55
	BuiltinOperator_ARG_MAX                      BuiltinOperator = 56
	BuiltinOperator_MINIMUM                      BuiltinOperator = 57
	BuiltinOperator_LESS                         BuiltinOperator = 58
	BuiltinOperator_NEG                          BuiltinOperator = 59
	BuiltinOperator_PADV2                        BuiltinOperator = 60
	BuiltinOperator_GREATER                      BuiltinOperator = 61
	BuiltinOperator_GREATER_EQUAL                BuiltinOperator = 62
	BuiltinOperator_LESS_EQUAL                   BuiltinOperator = 63
	BuiltinOperator_SELECT                       BuiltinOperator = 64
	BuiltinOperator_SLICE                        BuiltinOperator = 65
	BuiltinOperator_SIN                          BuiltinOperator = 66
	BuiltinOperator_TRANSPOSE_CONV               BuiltinOperator = 67
	BuiltinOperator_SPARSE_TO_DENSE              BuiltinOperator = 68
	BuiltinOperator_TILE                         BuiltinOperator = 69
	BuiltinOperator_EXPAND_DIMS                  BuiltinOperator = 70
	BuiltinOperator_EQUAL                        BuiltinOperator = 71
	BuiltinOperator_NOT_EQUAL                    BuiltinOperator = 72
	BuiltinOperator_LOG                          BuiltinOperator = 73
	BuiltinOperator_SUM                          BuiltinOperator = 74
	BuiltinOperator_SQRT                         BuiltinOperator = 75
	BuiltinOperator_RSQRT                        BuiltinOperator = 76
	BuiltinOperator_SHAPE                        BuiltinOperator = 77
	BuiltinOperator_POW                          BuiltinOperator = 78
	BuiltinOperator_ARG_MIN                      BuiltinOperator = 79
	BuiltinOperator_FAKE_QUANT                   BuiltinOperator = 80
	BuiltinOperator_REDUCE_PROD                  BuiltinOperator = 81
	BuiltinOperator_REDUCE_MAX                   BuiltinOperator = 82
	BuiltinOperator_PACK                         BuiltinOperator = 83
	BuiltinOperator_LOGICAL_OR                   BuiltinOperator = 84
	BuiltinOperator_ONE_HOT                      BuiltinOperator = 85
	BuiltinOperator_LOGICAL_AND                  BuiltinOperator = 86
	BuiltinOperator_LOGICAL_NOT                  BuiltinOperator = 87
	BuiltinOperator_UNPACK                       BuiltinOperator = 88
	BuiltinOperator_REDUCE_MIN                   BuiltinOperator = 89
	BuiltinOperator_FLOOR_DIV                    BuiltinOperator = 90
	BuiltinOperator_REDUCE_ANY                   BuiltinOperator = 91
	BuiltinOperator_SQUARE                       BuiltinOperator = 92
	BuiltinOperator_ZEROS_LIKE                   BuiltinOperator = 93
	BuiltinOperator_FILL                         BuiltinOperator = 94
	BuiltinOperator_FLOOR_MOD                    BuiltinOperator = 95
	BuiltinOperator_RANGE                        BuiltinOperator = 96
	BuiltinOperator_RESIZE_NEAREST_NEIGHBOR      BuiltinOperator = 97
	BuiltinOperator_LEAKY_RELU                   BuiltinOperator = 98
	BuiltinOperator_SQUARED_DIFFERENCE           BuiltinOperator = 99
	BuiltinOperator_MIRROR_PAD                   BuiltinOperator = 100
	BuiltinOperator_ABS                          BuiltinOperator = 101
	BuiltinOperator_SPLIT_V                      BuiltinOperator = 102
	BuiltinOperator_UNIQUE                       BuiltinOperator = 103
	BuiltinOperator_CEIL                         BuiltinOperator = 104
	BuiltinOperator_REVERSE_V2                   BuiltinOperator = 105
	BuiltinOperator_ADD_N                        BuiltinOperator = 106
	BuiltinOperator_GATHER_ND                    BuiltinOperator = 107
	BuiltinOperator_COS                          BuiltinOperator = 108
	BuiltinOperator_WHERE                        BuiltinOperator = 109
	BuiltinOperator_RANK                         BuiltinOperator = 110
	BuiltinOperator_ELU                          BuiltinOperator = 111
	BuiltinOperator_REVERSE_SEQUENCE             BuiltinOperator = 112
	BuiltinOperator_MATRIX_DIAG                  BuiltinOperator = 113
	BuiltinOperator_QUANTIZE                     BuiltinOperator = 114
	BuiltinOperator_MATRIX_SET_DIAG              BuiltinOperator = 115
	BuiltinOperator_MIN                          BuiltinOperator = BuiltinOperator_ADD
	BuiltinOperator_MAX                          BuiltinOperator = BuiltinOperator_MATRIX_SET_DIAG
)

type DynamicBuffer

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

DynamicBuffer is buffer hold multiple strings.

func (*DynamicBuffer) AddString

func (d *DynamicBuffer) AddString(s string)

AddString append to the dynamic buffer.

func (*DynamicBuffer) WriteToTensorAsVector

func (d *DynamicBuffer) WriteToTensorAsVector(t *Tensor)

WriteToTensorAsVector write buffer into the tensor as vector.

type ExpRegistration

type ExpRegistration struct {
	Init            unsafe.Pointer
	Free            unsafe.Pointer
	Prepare         unsafe.Pointer
	Invoke          unsafe.Pointer
	ProfilingString unsafe.Pointer
}

ExtRegistration indicate registration structure.

type Interpreter

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

Interpreter implement TfLiteInterpreter.

func NewInterpreter

func NewInterpreter(model *Model, options *InterpreterOptions) *Interpreter

NewInterpreter create new Interpreter.

func (*Interpreter) AllocateTensors

func (i *Interpreter) AllocateTensors() Status

AllocateTensor allocate tensors for the interpreter.

func (*Interpreter) Cancel added in v1.0.8

func (i *Interpreter) Cancel() Status

Cancel cancel the in-flight invocation. The Invoke call aborted this way returns an error status. Requires EnableCancellation on the options used to create the interpreter.

func (*Interpreter) Delete

func (i *Interpreter) Delete()

Delete delete instance of Interpreter.

func (*Interpreter) EnsureTensorDataIsReadable added in v1.0.8

func (i *Interpreter) EnsureTensorDataIsReadable(index int) Status

EnsureTensorDataIsReadable ensure the data of the tensor specified by index in the global tensor list is readable.

func (*Interpreter) GetInputTensor

func (i *Interpreter) GetInputTensor(index int) *Tensor

GetInputTensor return input tensor specified by index.

func (*Interpreter) GetInputTensorCount

func (i *Interpreter) GetInputTensorCount() int

GetInputTensorCount return number of input tensors.

func (*Interpreter) GetInputTensorIndex added in v1.0.8

func (i *Interpreter) GetInputTensorIndex(input_index int) int

GetInputTensorIndex return the index in the global tensor list of the input tensor specified by input_index.

func (*Interpreter) GetOutputTensor

func (i *Interpreter) GetOutputTensor(index int) *Tensor

GetOutputTensor return output tensor specified by index.

func (*Interpreter) GetOutputTensorCount

func (i *Interpreter) GetOutputTensorCount() int

GetOutputTensorCount return number of output tensors.

func (*Interpreter) GetOutputTensorIndex added in v1.0.8

func (i *Interpreter) GetOutputTensorIndex(output_index int) int

GetOutputTensorIndex return the index in the global tensor list of the output tensor specified by output_index.

func (*Interpreter) GetSignatureCount added in v1.0.8

func (i *Interpreter) GetSignatureCount() int

GetSignatureCount return the number of signatures defined in the model.

func (*Interpreter) GetSignatureKey added in v1.0.8

func (i *Interpreter) GetSignatureKey(index int) string

GetSignatureKey return the key of the signature specified by index.

func (*Interpreter) GetSignatureRunner added in v1.0.8

func (i *Interpreter) GetSignatureRunner(key string) *SignatureRunner

GetSignatureRunner return the runner for the signature specified by key. The returned runner must be deleted with Delete before the interpreter is deleted.

func (*Interpreter) GetTensor added in v1.0.8

func (i *Interpreter) GetTensor(index int) *Tensor

GetTensor return the tensor specified by index in the global tensor list of the interpreter.

func (*Interpreter) GetVariableTensor added in v1.0.8

func (i *Interpreter) GetVariableTensor(index int) *Tensor

GetVariableTensor return the variable tensor specified by index.

func (*Interpreter) GetVariableTensorCount added in v1.0.8

func (i *Interpreter) GetVariableTensorCount() int

GetVariableTensorCount return number of variable tensors associated with the interpreter.

func (*Interpreter) InputTensorIndices added in v1.0.8

func (i *Interpreter) InputTensorIndices() []int

InputTensorIndices return the tensor indices of the input tensors in the global tensor list of the interpreter.

func (*Interpreter) Invoke

func (i *Interpreter) Invoke() Status

Invoke invoke the task.

func (*Interpreter) ModifyGraphWithDelegate added in v1.0.8

func (i *Interpreter) ModifyGraphWithDelegate(d delegates.Delegater) Status

ModifyGraphWithDelegate apply the delegate to the interpreter after creation. Prefer passing delegates via InterpreterOptions.AddDelegate.

func (*Interpreter) OutputTensorIndices added in v1.0.8

func (i *Interpreter) OutputTensorIndices() []int

OutputTensorIndices return the tensor indices of the output tensors in the global tensor list of the interpreter.

func (*Interpreter) ResetVariableTensors

func (i *Interpreter) ResetVariableTensors() Status

ResetVariableTensors resets variable tensors.

func (*Interpreter) ResizeInputTensor

func (i *Interpreter) ResizeInputTensor(index int, dims []int32) Status

ResizeInputTensor resize the tensor specified by index with dims.

type InterpreterOptions

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

InterpreterOptions implement TfLiteInterpreterOptions.

func NewInterpreterOptions

func NewInterpreterOptions() *InterpreterOptions

NewInterpreterOptions create new InterpreterOptions.

func (*InterpreterOptions) AddDelegate

func (o *InterpreterOptions) AddDelegate(d delegates.Delegater)

func (*InterpreterOptions) Copy added in v1.0.8

Copy return a copy of the interpreter options.

func (*InterpreterOptions) Delete

func (o *InterpreterOptions) Delete()

Delete delete instance of InterpreterOptions.

func (*InterpreterOptions) EnableCancellation added in v1.0.8

func (o *InterpreterOptions) EnableCancellation(enable bool) Status

EnableCancellation enable or disable cancellation for the interpreter created with these options. When enabled, an in-flight Invoke call can be aborted with Interpreter.Cancel.

func (*InterpreterOptions) ExpAddBuiltinOp

func (o *InterpreterOptions) ExpAddBuiltinOp(op BuiltinOperator, reg *ExpRegistration, minVersion, maxVersion int)

ExpAddBuiltinOp add builtin op specified by code and registration. Current implementation is work in progress.

func (*InterpreterOptions) ExpAddCustomOp

func (o *InterpreterOptions) ExpAddCustomOp(name string, reg *ExpRegistration, minVersion, maxVersion int)

ExpAddCustomOp add custom op specified by name and registration. Current implementation is work in progress.

func (*InterpreterOptions) SetEnableDelegateFallback added in v1.0.8

func (o *InterpreterOptions) SetEnableDelegateFallback(enable bool)

SetEnableDelegateFallback enable or disable fallback to CPU when delegate application or invocation fails. When enabled and Invoke returns an error, the interpreter automatically falls back to not using any delegates.

func (*InterpreterOptions) SetErrorReporter

func (o *InterpreterOptions) SetErrorReporter(f func(string, interface{}), user_data interface{})

SetErrorRepoter set a function of reporter.

func (*InterpreterOptions) SetNumThread

func (o *InterpreterOptions) SetNumThread(num_threads int)

SetNumThread set number of threads.

func (*InterpreterOptions) SetUseNNAPI added in v1.0.2

func (o *InterpreterOptions) SetUseNNAPI(enable bool)

SetUseNNAPI enable or disable the NN API for the interpreter (true to enable).

type Model

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

Model is TfLiteModel.

func NewModel

func NewModel(model_data []byte) *Model

NewModel create new Model from buffer.

func NewModelFromFile

func NewModelFromFile(model_path string) *Model

NewModelFromFile create new Model from file data.

func NewModelFromFileWithErrorReporter added in v1.0.8

func NewModelFromFileWithErrorReporter(model_path string, f func(string, interface{}), user_data interface{}) *Model

NewModelFromFileWithErrorReporter create new Model from file data. The reporter is called with error messages produced while loading the model.

func NewModelWithErrorReporter added in v1.0.8

func NewModelWithErrorReporter(model_data []byte, f func(string, interface{}), user_data interface{}) *Model

NewModelWithErrorReporter create new Model from buffer. The reporter is called with error messages produced while loading the model.

func (*Model) Delete

func (m *Model) Delete()

Delete delete instance of model.

type QuantizationParams

type QuantizationParams struct {
	Scale     float64
	ZeroPoint int
}

QuantizationParams implement TfLiteQuantizationParams.

type SignatureRunner added in v1.0.8

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

SignatureRunner implement TfLiteSignatureRunner. It is used to run inference on a specific SavedModel signature.

func (*SignatureRunner) AllocateTensors added in v1.0.8

func (r *SignatureRunner) AllocateTensors() Status

AllocateTensors allocate tensors for the signature runner.

func (*SignatureRunner) Cancel added in v1.0.8

func (r *SignatureRunner) Cancel() Status

Cancel cancel the in-flight invocation of the signature runner. Requires EnableCancellation on the options used to create the interpreter.

func (*SignatureRunner) Delete added in v1.0.8

func (r *SignatureRunner) Delete()

Delete delete instance of the signature runner.

func (*SignatureRunner) GetInputCount added in v1.0.8

func (r *SignatureRunner) GetInputCount() int

GetInputCount return number of inputs of the signature.

func (*SignatureRunner) GetInputName added in v1.0.8

func (r *SignatureRunner) GetInputName(index int) string

GetInputName return name of the input specified by index.

func (*SignatureRunner) GetInputTensor added in v1.0.8

func (r *SignatureRunner) GetInputTensor(name string) *Tensor

GetInputTensor return the input tensor specified by name.

func (*SignatureRunner) GetOutputCount added in v1.0.8

func (r *SignatureRunner) GetOutputCount() int

GetOutputCount return number of outputs of the signature.

func (*SignatureRunner) GetOutputName added in v1.0.8

func (r *SignatureRunner) GetOutputName(index int) string

GetOutputName return name of the output specified by index.

func (*SignatureRunner) GetOutputTensor added in v1.0.8

func (r *SignatureRunner) GetOutputTensor(name string) *Tensor

GetOutputTensor return the output tensor specified by name.

func (*SignatureRunner) Invoke added in v1.0.8

func (r *SignatureRunner) Invoke() Status

Invoke run the signature.

func (*SignatureRunner) ResizeInputTensor added in v1.0.8

func (r *SignatureRunner) ResizeInputTensor(name string, dims []int32) Status

ResizeInputTensor resize the input tensor specified by name with dims.

type Status

type Status int

State implement TfLiteStatus.

const (
	OK Status = 0
	Error
)

func (Status) String

func (i Status) String() string

type Tensor

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

Tensor implement TfLiteTensor.

func (*Tensor) ByteSize

func (t *Tensor) ByteSize() uint

ByteSize return byte size of the tensor.

func (*Tensor) CopyFromBuffer

func (t *Tensor) CopyFromBuffer(b interface{}) Status

CopyFromBuffer write buffer to the tensor.

func (*Tensor) CopyToBuffer

func (t *Tensor) CopyToBuffer(b interface{}) Status

CopyToBuffer write buffer from the tensor.

func (*Tensor) Data

func (t *Tensor) Data() unsafe.Pointer

Data return pointer of buffer.

func (*Tensor) Dim

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

Dim return dimension of the element specified by index.

func (*Tensor) Float32At

func (t *Tensor) Float32At(at ...int) float32

Float32At returns float32 value located in the dimension.

func (*Tensor) Float32s

func (t *Tensor) Float32s() []float32

Float32s returns float32s.

func (*Tensor) GetString

func (t *Tensor) GetString(index int) string

GetString returns string in the string buffer.

func (*Tensor) Int8s

func (t *Tensor) Int8s() []int8

Int8s returns int8s.

func (*Tensor) Int16s

func (t *Tensor) Int16s() []int16

Int16s returns int16s.

func (*Tensor) Int32s

func (t *Tensor) Int32s() []int32

Int32s returns int32s.

func (*Tensor) Int64s

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

Int64s returns int64s.

func (*Tensor) Name

func (t *Tensor) Name() string

Name return name of the tensor.

func (*Tensor) NumDims

func (t *Tensor) NumDims() int

NumDims return number of dimensions.

func (*Tensor) QuantizationParams

func (t *Tensor) QuantizationParams() QuantizationParams

QuantizationParams return quantization parameters of the tensor.

func (*Tensor) SetFloat32s

func (t *Tensor) SetFloat32s(v []float32) error

SetFloat32s sets float32s.

func (*Tensor) SetInt8s

func (t *Tensor) SetInt8s(v []int8) error

SetInt8s sets int8s.

func (*Tensor) SetInt16s

func (t *Tensor) SetInt16s(v []int16) error

SetInt16s sets int16s.

func (*Tensor) SetInt32s

func (t *Tensor) SetInt32s(v []int32) error

SetInt32s sets int32s.

func (*Tensor) SetInt64s

func (t *Tensor) SetInt64s(v []int64) error

SetInt64s sets int64s.

func (*Tensor) SetUint8s

func (t *Tensor) SetUint8s(v []uint8) error

SetUint8s sets uint8s.

func (*Tensor) Shape added in v1.0.2

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

Shape return shape of the tensor.

func (*Tensor) String

func (t *Tensor) String() string

String returns name of tensor.

func (*Tensor) Type

func (t *Tensor) Type() TensorType

Type return TensorType.

func (*Tensor) UInt8s

func (t *Tensor) UInt8s() []uint8

UInt8s returns uint8s.

type TensorType

type TensorType int

TensorType is types of the tensor.

const (
	NoType    TensorType = 0
	Float32   TensorType = 1
	Int32     TensorType = 2
	UInt8     TensorType = 3
	Int64     TensorType = 4
	String    TensorType = 5
	Bool      TensorType = 6
	Int16     TensorType = 7
	Complex64 TensorType = 8
	Int8      TensorType = 9
)

func (TensorType) String

func (i TensorType) String() string

Directories

Path Synopsis
_example
fizzbuzz command
iris command
sin command
smartreply command
qa module
xor_embedded module
lib module

Jump to

Keyboard shortcuts

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