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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-10 UTC."],[],[],null,["# TensorFlowLiteSwift Framework Reference\n\nInterpreter\n===========\n\n public final class Interpreter\n\nA TensorFlow Lite interpreter that performs inference from a given model.\n- `\n ``\n ``\n `\n\n ### [options](#/s:19TensorFlowLiteSwift11InterpreterC7optionsAC7OptionsVSgvp)\n\n `\n ` \n The configuration options for the `Interpreter`. \n\n #### Declaration\n\n Swift \n\n public let options: ../Classes/Interpreter/Options.html?\n\n- `\n ``\n ``\n `\n\n ### [delegates](#/s:19TensorFlowLiteSwift11InterpreterC9delegatesSayAA8Delegate_pGSgvp)\n\n `\n ` \n An `Array` of [Delegate](../Protocols/Delegate.html)s for the `Interpreter` to use to perform graph operations. \n\n #### Declaration\n\n Swift \n\n public let delegates: [../Protocols/Delegate.html]?\n\n- `\n ``\n ``\n `\n\n ### [inputTensorCount](#/s:19TensorFlowLiteSwift11InterpreterC05inputA5CountSivp)\n\n `\n ` \n The total number of input [Tensor](../Structs/Tensor.html)s associated with the model. \n\n #### Declaration\n\n Swift \n\n public var inputTensorCount: Int { get }\n\n- `\n ``\n ``\n `\n\n ### [outputTensorCount](#/s:19TensorFlowLiteSwift11InterpreterC06outputA5CountSivp)\n\n `\n ` \n The total number of output [Tensor](../Structs/Tensor.html)s associated with the model. \n\n #### Declaration\n\n Swift \n\n public var outputTensorCount: Int { get }\n\n- `\n ``\n ``\n `\n\n ### [init(modelPath:options:delegates:)](#/s:19TensorFlowLiteSwift11InterpreterC9modelPath7options9delegatesACSS_AC7OptionsVSgSayAA8Delegate_pGSgtKcfc)\n\n `\n ` \n Creates a new instance with the given values. \n Throws\n An error if the model could not be loaded or the interpreter could not be created. \n\n #### Declaration\n\n Swift \n\n public init(modelPath: String, options: ../Classes/Interpreter/Options.html? = nil, delegates: [../Protocols/Delegate.html]? = nil) throws\n\n #### Parameters\n\n |-------------------|----------------------------------------------------------------------------------------------------------------------------------------|\n | ` `*modelPath*` ` | The local file path to a TensorFlow Lite model. |\n | ` `*options*` ` | Configurations for the `Interpreter`. The default is `nil` indicating that the `Interpreter` will determine the configuration options. |\n | ` `*delegate*` ` | `Array` of [Delegate](../Protocols/Delegate.html)s for the `Interpreter` to use to perform graph operations. The default is `nil`. |\n\n- `\n ``\n ``\n `\n\n ### [invoke()](#/s:19TensorFlowLiteSwift11InterpreterC6invokeyyKF)\n\n `\n ` \n Invokes the interpreter to perform inference from the loaded graph. \n Throws\n An error if the model was not ready because the tensors were not allocated. \n\n #### Declaration\n\n Swift \n\n public func invoke() throws\n\n- `\n ``\n ``\n `\n\n ### [input(at:)](#/s:19TensorFlowLiteSwift11InterpreterC5input2atAA0A0VSi_tKF)\n\n `\n ` \n Returns the input [Tensor](../Structs/Tensor.html) at the given index. \n Throws\n An error if the index is invalid or the tensors have not been allocated. \n\n #### Declaration\n\n Swift \n\n public func input(at index: Int) throws -\u003e ../Structs/Tensor.html\n\n #### Parameters\n\n |---------------|-----------------------------------------------------------|\n | ` `*index*` ` | The index for the input [Tensor](../Structs/Tensor.html). |\n\n #### Return Value\n\n The input [Tensor](../Structs/Tensor.html) at the given index.\n- `\n ``\n ``\n `\n\n ### [output(at:)](#/s:19TensorFlowLiteSwift11InterpreterC6output2atAA0A0VSi_tKF)\n\n `\n ` \n Returns the output [Tensor](../Structs/Tensor.html) at the given index. \n Throws\n 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. \n\n #### Declaration\n\n Swift \n\n public func output(at index: Int) throws -\u003e ../Structs/Tensor.html\n\n #### Parameters\n\n |---------------|------------------------------------------------------------|\n | ` `*index*` ` | The index for the output [Tensor](../Structs/Tensor.html). |\n\n #### Return Value\n\n The output [Tensor](../Structs/Tensor.html) at the given index.\n- `\n ``\n ``\n `\n\n ### [resizeInput(at:to:)](#/s:19TensorFlowLiteSwift11InterpreterC11resizeInput2at2toySi_AA0A0V5ShapeVtKF)\n\n `\n ` \n Resizes the input [Tensor](../Structs/Tensor.html) at the given index to the specified [Tensor.Shape](../Structs/Tensor/Shape.html). \n Note\n After resizing an input tensor, the client **must** explicitly call [allocateTensors()](../Classes/Interpreter.html#/s:19TensorFlowLiteSwift11InterpreterC15allocateTensorsyyKF) before attempting to access the resized tensor data or invoking the interpreter to perform inference. \n Throws\n An error if the input tensor at the given index could not be resized. \n\n #### Declaration\n\n Swift \n\n public func resizeInput(at index: Int, to shape: ../Structs/Tensor.html.Shape) throws\n\n #### Parameters\n\n |---------------|--------------------------------------------------------------------|\n | ` `*index*` ` | The index for the input [Tensor](../Structs/Tensor.html). |\n | ` `*shape*` ` | The shape to resize the input [Tensor](../Structs/Tensor.html) to. |\n\n- `\n ``\n ``\n `\n\n ### [copy(_:toInputAt:)](#/s:19TensorFlowLiteSwift11InterpreterC4copy_9toInputAtAA0A0V10Foundation4DataV_SitKF)\n\n `\n ` \n Copies the given data to the input [Tensor](../Structs/Tensor.html) at the given index. \n Throws\n An error if the `data.count` does not match the input tensor's `data.count` or if the given index is invalid. \n\n #### Declaration\n\n Swift \n\n @discardableResult\n public func copy(_ data: Data, toInputAt index: Int) throws -\u003e ../Structs/Tensor.html\n\n #### Parameters\n\n |---------------|------------------------------------------------------------------------------------|\n | ` `*data*` ` | The data to be copied to the input [Tensor](../Structs/Tensor.html)'s data buffer. |\n | ` `*index*` ` | The index for the input [Tensor](../Structs/Tensor.html). |\n\n #### Return Value\n\n The input [Tensor](../Structs/Tensor.html) with the copied data.\n- `\n ``\n ``\n `\n\n ### [allocateTensors()](#/s:19TensorFlowLiteSwift11InterpreterC15allocateTensorsyyKF)\n\n `\n ` \n Allocates memory for all input [Tensor](../Structs/Tensor.html)s based on their [Tensor.Shape](../Structs/Tensor/Shape.html)s. \n Note\n This is a relatively expensive operation and should only be called after creating the interpreter and resizing any input tensors. \n Throws\n An error if memory could not be allocated for the input tensors. \n\n #### Declaration\n\n Swift \n\n public func allocateTensors() throws\n\n- `\n ``\n ``\n `\n\n ### [Options](../Classes/Interpreter/Options.html)\n\n `\n ` \n Options for configuring the [Interpreter](../Classes/Interpreter.html). \n\n #### Declaration\n\n Swift \n\n public struct Options : Equatable, Hashable"]]