-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.go
53 lines (47 loc) · 1.32 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package tflite
/*
#include <stdio.h>
#include <tensorflow/lite/c/c_api.h>
#cgo LDFLAGS: -ltensorflowlite_c
#cgo linux LDFLAGS: -lm -ldl -lrt
*/
import "C"
import (
"unsafe"
)
// InterpreterOptions represents a TensorFlow Lite InterpreterOptions.
type InterpreterOptions struct {
options *C.TfLiteInterpreterOptions
}
// NewInterpreterOptions creates new InterpreterOptions.
func NewInterpreterOptions() (*InterpreterOptions, error) {
o := C.TfLiteInterpreterOptionsCreate()
if o == nil {
return nil, ErrCreateInterpreterOptions
}
return &InterpreterOptions{options: o}, nil
}
// Delete delete instance of InterpreterOptions.
func (o *InterpreterOptions) Delete() error {
if o != nil {
C.TfLiteInterpreterOptionsDelete(o.options)
return nil
}
return ErrDeleteIntepreterOptions
}
// SetNumThread set number of threads.
func (o *InterpreterOptions) SetNumThread(numThreads int) error {
if o != nil {
C.TfLiteInterpreterOptionsSetNumThreads(o.options, C.int32_t(numThreads))
return nil
}
return ErrInterpreterSetNumThread
}
// AddDelegate add the option of a delegate for the TensorFlow Lite interpreter
func (o *InterpreterOptions) AddDelegate(d *Delegate) error {
if o != nil {
C.TfLiteInterpreterOptionsAddDelegate(o.options, (*C.TfLiteDelegate)(unsafe.Pointer(d)))
return nil
}
return ErrInterpreterAddDelegate
}