Protocols

The following protocols are available globally.

  • A TIOData is any data type that knows how to provide bytes to a input tensor and how to read bytes from an output tensor.

    See more

    Declaration

    Objective-C

    @protocol TIOData <NSObject>

    Swift

    protocol TIOData : NSObjectProtocol
  • Describes an input or output layer. Used internally by a model when parsing its description.

    A layer description encapsulates information about an input or output tensor that is needed to prepare obj-c data and copy bytes into and out of it. For example, a vector layer description for an input tensor describes any transformations the submitted data must undergo before the underlying bytes are copied to the tensor, e.g. quantization and normalization, as well as the shape of the expected input, which determines how many bytes are copied into the tensor.

    See more

    Declaration

    Objective-C

    @protocol TIOLayerDescription <NSObject>

    Swift

    protocol TIOLayerDescription : NSObjectProtocol
  • An Obj-C wrapper around lower level, usually C++ model implementations. This is the primary API provided by the TensorIO framework.

    A TIOModel is built from a bundle folder that contains the underlying model, a json description of the model’s input and output layers, and any additional assets required by the model, for example, output labels.

    A conforming TIOModel begins by parsing a json description of the model’s input and output layers, producing a TIOLayerInterface for each layer. Each layer is fully described by a conforming TIOLayerDescription, which describes the data the layer expects or produces, for example, whether it is quantized, any transformations that should be applied to it, and the number of bytes the layer expects.

    To perform inference with the underlying model, call runOn: with a conforming TIOData object. TIOData objects simply know how to copy bytes to and receive bytes from a model’s input and output layers. Internally, this method matches TIOData objects with their corresponding layers and ensures that bytes are copied to the right place. The runOn: method then returns a conforming TIOData object, which is the result of performing inference with the model. Objects that conform to the TIOData protocol include NSNumber, NSArray, NSData, NSDictionary, and TIOPixelBuffer, which wraps a CVPixelBuffer for computer vision models.

    For more information about a model’s interface, refer to the TIOLayerInterface and TIOLayerDescription classes. For more information about the kinds of Objective-C data a TIOModel can work with, refer to the TIOData protocol and its conforming classes. For more information about the JSON file which describes a model, see TIOModelBundleJSONSchema.h

    Note that, currently, only TensorFlow Lite (TFLite) models are supported.

    @warning Models are not thread safe. Models may be used on separate threads, so that you can perform inference off the main thread, but you should not use the same model from multiple threads.

    See more

    Declaration

    Objective-C

    @protocol TIOModel <NSObject>

    Swift

    protocol TIOModel : NSObjectProtocol