# Interpreter

    public final class Interpreter

A TensorFlow Lite interpreter that performs inference from a given model.
- `


  ### [options](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC7optionsAC7OptionsVSgvp)


  ` The configuration options for the `Interpreter`.

  #### Declaration

  Swift

      public let options: https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter/Options.html?

- `


  ### [delegates](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC9delegatesSayAA8Delegate_pGSgvp)


  ` An `Array` of `https://developers.google.com/edge/api/tflite/swift/Protocols/Delegate.html`s for the `Interpreter` to use to perform graph operations.

  #### Declaration

  Swift

      public let delegates: [https://developers.google.com/edge/api/tflite/swift/Protocols/Delegate.html]?

- `


  ### [inputTensorCount](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC05inputA5CountSivp)


  ` The total number of input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`s associated with the model.

  #### Declaration

  Swift

      public var inputTensorCount: Int { get }

- `


  ### [outputTensorCount](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC06outputA5CountSivp)


  ` The total number of output `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`s associated with the model.

  #### Declaration

  Swift

      public var outputTensorCount: Int { get }

- `


  ### [init(modelPath:options:delegates:)](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC9modelPath7options9delegatesACSS_AC7OptionsVSgSayAA8Delegate_pGSgtKcfc)


  ` 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.

  #### Declaration

  Swift

      public init(modelPath: String, options: https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter/Options.html? = nil, delegates: [https://developers.google.com/edge/api/tflite/swift/Protocols/Delegate.html]? = nil) throws

  #### Parameters

  |---|---|
  | ` 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 `https://developers.google.com/edge/api/tflite/swift/Protocols/Delegate.html`s for the `Interpreter` to use to perform graph operations. The default is `nil`. |

- `


  ### [invoke()](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC6invokeyyKF)


  ` 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.

  #### Declaration

  Swift

      public func invoke() throws

- `


  ### [input(at:)](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC5input2atAA0A0VSi_tKF)


  ` Returns the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` at the given index.
  Throws
  An error if the index is invalid or the tensors have not been allocated.

  #### Declaration

  Swift

      public func input(at index: Int) throws -> https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html

  #### Parameters

  |---|---|
  | ` index ` | The index for the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`. |

  #### Return Value

  The input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` at the given index.
- `


  ### [output(at:)](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC6output2atAA0A0VSi_tKF)


  ` Returns the output `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` 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.

  #### Declaration

  Swift

      public func output(at index: Int) throws -> https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html

  #### Parameters

  |---|---|
  | ` index ` | The index for the output `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`. |

  #### Return Value

  The output `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` at the given index.
- `


  ### [resizeInput(at:to:)](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC11resizeInput2at2toySi_AA0A0V5ShapeVtKF)


  ` Resizes the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` at the given index to the specified `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor/Shape.html`.
  Note
  After resizing an input tensor, the client **must** explicitly call `https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter.html#/s:19TensorFlowLiteSwift11InterpreterC15allocateTensorsyyKF` 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.

  #### Declaration

  Swift

      public func resizeInput(at index: Int, to shape: https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html.Shape) throws

  #### Parameters

  |---|---|
  | ` index ` | The index for the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`. |
  | ` shape ` | The shape to resize the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` to. |

- `


  ### [copy(_:toInputAt:)](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC4copy_9toInputAtAA0A0V10Foundation4DataV_SitKF)


  ` Copies the given data to the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` 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.

  #### Declaration

  Swift

      @discardableResult
      public func copy(_ data: Data, toInputAt index: Int) throws -> https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html

  #### Parameters

  |---|---|
  | ` data ` | The data to be copied to the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`'s data buffer. |
  | ` index ` | The index for the input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`. |

  #### Return Value

  The input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html` with the copied data.
- `


  ### [allocateTensors()](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter#/s:19TensorFlowLiteSwift11InterpreterC15allocateTensorsyyKF)


  ` Allocates memory for all input `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor.html`s based on their `https://developers.google.com/edge/api/tflite/swift/Structs/Tensor/Shape.html`s.
  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.

  #### Declaration

  Swift

      public func allocateTensors() throws

- `


  ### [Options](https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter/Options.html)


  ` Options for configuring the `https://developers.google.com/edge/api/tflite/swift/Classes/Interpreter.html`.

  #### Declaration

  Swift

      public struct Options : Equatable, Hashable