tensorflow/lite/g3doc/api_docs/swift/Classes/Interpreter.html
public final class Interpreter
A TensorFlow Lite interpreter that performs inference from a given model.
`
options
`
The configuration options for the Interpreter.
Swift
public let options: Options?
`
delegates
`
An Array of Delegates for the Interpreter to use to perform graph operations.
Swift
public let delegates: [Delegate]?
`
inputTensorCount
`
The total number of input Tensors associated with the model.
Swift
public var inputTensorCount: Int { get }
`
outputTensorCount
`
The total number of output Tensors associated with the model.
Swift
public var outputTensorCount: Int { get }
`
init(modelPath:options:delegates:)
`
Creates a new instance with the given values.
Throws
An error if the model could not be loaded or the interpreter could not be created.
Swift
public init(modelPath: String, options: Options? = nil, delegates: [Delegate]? = nil) throws
| modelPath |
The local file path to a TensorFlow Lite model.
|
| options |
Configurations for the Interpreter. The default is nil indicating that the Interpreter will determine the configuration options.
|
| delegate |
Array of Delegates for the Interpreter to use to perform graph operations. The default is nil.
|
`
invoke()
`
Invokes the interpreter to perform inference from the loaded graph.
Throws
An error if the model was not ready because the tensors were not allocated.
Swift
public func invoke() throws
`
input(at:)
`
Returns the input Tensor at the given index.
Throws
An error if the index is invalid or the tensors have not been allocated.
Swift
public func input(at index: Int) throws -> Tensor
| index |
The index for the input Tensor.
|
The input Tensor at the given index.
`
output(at:)
`
Returns the output Tensor at the given index.
Throws
An error if the index is invalid, tensors haven’t been allocated, or interpreter has not been invoked for models that dynamically compute output tensors based on the values of its input tensors.
Swift
public func output(at index: Int) throws -> Tensor
| index |
The index for the output Tensor.
|
The output Tensor at the given index.
`
resizeInput(at:to:)
`
Resizes the input Tensor at the given index to the specified Tensor.Shape.
Note
After resizing an input tensor, the client must explicitly call allocateTensors() before attempting to access the resized tensor data or invoking the interpreter to perform inference.
Throws
An error if the input tensor at the given index could not be resized.
Swift
public func resizeInput(at index: Int, to shape: Tensor.Shape) throws
| index |
The index for the input Tensor.
|
| shape |
The shape to resize the input Tensor to.
|
`
copy(_:toInputAt:)
`
Copies the given data to the input Tensor at the given index.
Throws
An error if the data.count does not match the input tensor’s data.count or if the given index is invalid.
Swift
@discardableResult
public func copy(_ data: Data, toInputAt index: Int) throws -> Tensor
| data |
The data to be copied to the input Tensor‘s data buffer.
|
| index |
The index for the input Tensor.
|
The input Tensor with the copied data.
`
allocateTensors()
`
Allocates memory for all input Tensors based on their Tensor.Shapes.
Note
This is a relatively expensive operation and should only be called after creating the interpreter and resizing any input tensors.
Throws
An error if memory could not be allocated for the input tensors.
Swift
public func allocateTensors() throws
`
Options
`
Options for configuring the Interpreter.
Swift
public struct Options : Equatable, Hashable