TIOVectorLayerDescription

@interface TIOVectorLayerDescription : NSObject <TIOLayerDescription>

The description of a vector (array) input or output later.

Vector inputs and outputs are always unrolled vectors, and from the tensor’s perspective they are just an array of bytes. The total length of a vector will be the total volume of the layer. For example, if an input layer is a tensor of shape (24,24,2), the length of the vector will be 24x24x2 = 1152.

TensorFlow Lite models expect row major ordering of bytes, such that higher order dimensions are traversed first. For example, a 2x4 matrix with the following values:

@code [[1 2 3 4] [5 6 7 8]] @endcode

should be unrolled and provided to the model as:

@code [1 2 3 4 5 6 7 8] @endcode

i.e, start with the row and traverse the columns before moving to the next row.

Because output layers are also exposed as an array of bytes, a TIOTFLiteModel will always return a vector in one dimension. If is up to you to reshape it if required.

@warning A TIOVectorLayerDescription‘s length is different than the byte length of a TIOData object. For example a quantized TIOVector (uint8_t) of length 4 will occupy 4 bytes of memory but an unquantized TIOVector (float_t) of length 4 will occupy 16 bytes of memory.

  • YES if the layer is quantized, NO otherwise

    Declaration

    Objective-C

    @property (readonly, getter=isQuantized, atomic) BOOL quantized;

    Swift

    var isQuantized: Bool { get }
  • The length of the vector in terms of its number of elements.

    Declaration

    Objective-C

    @property (readonly, atomic) NSUInteger length;

    Swift

    var length: UInt { get }
  • Indexed labels corresponding to the indexed output of a layer. May be nil.

    Labeling the output of a model is such a common operation that support for it is included by default.

    Declaration

    Objective-C

    @property (readonly, copy, atomic, nullable) NSArray<NSString *> *labels;

    Swift

    var labels: [String]? { get }
  • YES if there are labels associated with this layer, NO otherwise.

    Declaration

    Objective-C

    @property (readonly, getter=isLabeled, atomic) BOOL labeled;

    Swift

    var isLabeled: Bool { get }
  • A function that converts a vector from unquantized values to quantized values

    Declaration

    Objective-C

    @property (readonly, atomic, nullable) TIODataQuantizer quantizer;

    Swift

    var quantizer: TIODataQuantizer? { get }
  • A function that converts a vector from quantized values to unquantized values

    Declaration

    Objective-C

    @property (readonly, atomic, nullable) TIODataDequantizer dequantizer;

    Swift

    var dequantizer: TIODataDequantizer? { get }
  • Designated initializer. Creates a vector description from the properties parsed in a model.json file.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithLength:(NSUInteger)length
                                    labels:(nullable NSArray<NSString *> *)labels
                                 quantized:(BOOL)quantized
                                 quantizer:(nullable TIODataQuantizer)quantizer
                               dequantizer:(nullable TIODataDequantizer)dequantizer;

    Swift

    init(length: UInt, labels: [String]?, quantized: Bool, quantizer: TIODataQuantizer?, dequantizer: TIODataDequantizer? = nil)

    Parameters

    length

    The total number of elements in this layer.

    labels

    The indexed labels associated with the outputs of this layer. May be nil.

    quantizer

    A function that transforms unquantized values to quantized input

    dequantizer

    A function that transforms quantized output to unquantized values

    Return Value

    instancetype A read-only instance of TIOVectorLayerDescription

  • Unavailable

    Use the designated initializer.

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Given the output vector of a tensor, returns labeled outputs using labels.

    labels must not be nil.

    Declaration

    Objective-C

    - (nonnull NSDictionary<NSString *, NSNumber *> *)labeledValues:
        (nonnull TIOVector *)vector;

    Swift

    func labeledValues(_ vector: [NSNumber]) -> [String : NSNumber]

    Parameters

    vector

    A TIOVector of values.

    Return Value

    NSDictionary The labeled values, where the dictionary keys are the labels and the dictionary values are the associated vector values.