chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
@@ -0,0 +1,87 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "TFLDelegate.h"
NS_ASSUME_NONNULL_BEGIN
/**
* @enum TFLCoreMLDelegateEnabledDevices
* This enum specifies for which devices the Core ML delegate will be enabled.
*/
typedef NS_ENUM(NSUInteger, TFLCoreMLDelegateEnabledDevices) {
/** Enables the delegate for devices with Neural Engine only. */
TFLCoreMLDelegateEnabledDevicesNeuralEngine,
/** Enables the delegate for all devices. */
TFLCoreMLDelegateEnabledDevicesAll,
};
/** Custom configuration options for a Core ML delegate. */
@interface TFLCoreMLDelegateOptions : NSObject
/**
* Indicates which devices the Core ML delegate should be enabled for. The default value is
* `TFLCoreMLDelegateEnabledDevicesNeuralEngine`, indicating that the delegate is enabled for
* Neural Engine devices only.
*/
@property(nonatomic) TFLCoreMLDelegateEnabledDevices enabledDevices;
/**
* Target Core ML version for the model conversion. When it's not set, Core ML version will be set
* to highest available version for the platform.
*/
@property(nonatomic) NSUInteger coreMLVersion;
/**
* The maximum number of Core ML delegate partitions created. Each graph corresponds to one
* delegated node subset in the TFLite model. The default value is `0` indicating that all possible
* partitions are delegated.
*/
@property(nonatomic) NSUInteger maxDelegatedPartitions;
/**
* The minimum number of nodes per partition to be delegated by the Core ML delegate. The default
* value is `2`.
*/
@property(nonatomic) NSUInteger minNodesPerPartition;
@end
/** A delegate that uses the Core ML framework for performing TensorFlow Lite graph operations. */
@interface TFLCoreMLDelegate : TFLDelegate
/**
* Initializes a new Core ML delegate with default options.
*
* @return A Core ML delegate initialized with default options. `nil` when the delegate creation
* fails. For example, trying to initialize a Core ML delegate on an unsupported device.
*/
- (nullable instancetype)init;
/**
* Initializes a new Core ML delegate with the given options.
*
* @param options Core ML delegate options.
*
* @return A Core ML delegate initialized with default options. `nil` when the delegate creation
* fails. For example, trying to initialize Core ML delegate on an unsupported device.
*/
- (nullable instancetype)initWithOptions:(TFLCoreMLDelegateOptions *)options
NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
+28
View File
@@ -0,0 +1,28 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
typedef void* TFLCDelegate;
NS_ASSUME_NONNULL_BEGIN
@interface TFLDelegate : NSObject
/** Pointer to underlying TfLiteDelegate*. */
@property(nonatomic, readonly) TFLCDelegate cDelegate;
@end
NS_ASSUME_NONNULL_END
+217
View File
@@ -0,0 +1,217 @@
// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
@class TFLDelegate;
@class TFLInterpreterOptions;
@class TFLSignatureRunner;
@class TFLTensor;
NS_ASSUME_NONNULL_BEGIN
/**
* @enum TFLInterpreterErrorCode
* This enum specifies various error codes related to `TFLInterpreter`.
*/
typedef NS_ENUM(NSUInteger, TFLInterpreterErrorCode) {
/** Provided tensor index is invalid. */
TFLInterpreterErrorCodeInvalidTensorIndex,
/** Input data has invalid byte size. */
TFLInterpreterErrorCodeInvalidInputByteSize,
/** Provided shape is invalid. It must be a non-empty array of positive unsigned integers. */
TFLInterpreterErrorCodeInvalidShape,
/** Provided model cannot be loaded. */
TFLInterpreterErrorCodeFailedToLoadModel,
/** Failed to create `TFLInterpreter`. */
TFLInterpreterErrorCodeFailedToCreateInterpreter,
/** Failed to invoke `TFLInterpreter`. */
TFLInterpreterErrorCodeFailedToInvoke,
/** Failed to retrieve a tensor. */
TFLInterpreterErrorCodeFailedToGetTensor,
/** Invalid tensor. */
TFLInterpreterErrorCodeInvalidTensor,
/** Failed to resize an input tensor. */
TFLInterpreterErrorCodeFailedToResizeInputTensor,
/** Failed to copy data into an input tensor. */
TFLInterpreterErrorCodeFailedToCopyDataToInputTensor,
/** Copying data into an output tensor not allowed. */
TFLInterpreterErrorCodeCopyDataToOutputTensorNotAllowed,
/** Failed to get data from a tensor. */
TFLInterpreterErrorCodeFailedToGetDataFromTensor,
/** Failed to allocate memory for tensors. */
TFLInterpreterErrorCodeFailedToAllocateTensors,
/** Operation not allowed without allocating memory for tensors first. */
TFLInterpreterErrorCodeAllocateTensorsRequired,
/** Operation not allowed without invoking the interpreter first. */
TFLInterpreterErrorCodeInvokeInterpreterRequired,
};
/**
* A TensorFlow Lite model interpreter.
*
* Note: Interpreter instances are *not* thread-safe.
*/
@interface TFLInterpreter : NSObject
/** The total number of input tensors. 0 if the interpreter creation failed. */
@property(nonatomic, readonly) NSUInteger inputTensorCount;
/** The total number of output tensors. 0 if the interpreter creation failed. */
@property(nonatomic, readonly) NSUInteger outputTensorCount;
/** An ordered list of the SignatureDef exported method names available in the model. */
@property(nonatomic, readonly) NSArray<NSString *> *signatureKeys;
/** Unavailable. */
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
/**
* Initializes a new TensorFlow Lite interpreter instance with the given model file path and the
* default interpreter options.
*
* @param modelPath An absolute path to a TensorFlow Lite model file stored locally on the device.
* @param error An optional error parameter populated when there is an error in initializing the
* interpreter.
*
* @return A new instance of `TFLInterpreter` with the given model and the default interpreter
* options. `nil` if there is an error in initializing the interpreter.
*/
- (nullable instancetype)initWithModelPath:(NSString *)modelPath error:(NSError **)error;
/**
* Initializes a new TensorFlow Lite interpreter instance with the given model file path and
* options.
*
* @param modelPath An absolute path to a TensorFlow Lite model file stored locally on the device.
* @param options Options to use for configuring the TensorFlow Lite interpreter.
* @param error An optional error parameter populated when there is an error in initializing the
* interpreter.
*
* @return A new instance of `TFLInterpreter` with the given model and options. `nil` if there is an
* error in initializing the interpreter.
*/
- (nullable instancetype)initWithModelPath:(NSString *)modelPath
options:(TFLInterpreterOptions *)options
error:(NSError **)error;
/**
* Initializes a new TensorFlow Lite interpreter instance with the given model file path, options
* and delegates.
*
* @param modelPath An absolute path to a TensorFlow Lite model file stored locally on the device.
* @param options Options to use for configuring the TensorFlow Lite interpreter.
* @param delegates Delegates to use with the TensorFlow Lite interpreter. When the array is empty,
* no delegate will be applied.
* @param error An optional error parameter populated when there is an error in initializing the
* interpreter.
*
* @return A new instance of `TFLInterpreter` with the given model and options. `nil` if there is an
* error in initializing the interpreter.
*/
- (nullable instancetype)initWithModelPath:(NSString *)modelPath
options:(TFLInterpreterOptions *)options
delegates:(NSArray<TFLDelegate *> *)delegates
error:(NSError **)error NS_DESIGNATED_INITIALIZER;
/**
* Invokes the interpreter to run inference.
*
* @param error An optional error parameter populated when there is an error in invoking the
* interpreter.
*
* @return Whether the invocation is successful. Returns NO if an error occurred.
*/
- (BOOL)invokeWithError:(NSError **)error;
/**
* Returns the input tensor at the given index.
*
* @param index The index of an input tensor.
* @param error An optional error parameter populated when there is an error in looking up the input
* tensor.
*
* @return The input tensor at the given index. `nil` if there is an error. See the `TFLTensor`
* class documentation for more details on the life expectancy between the returned tensor and
* this interpreter.
*/
- (nullable TFLTensor *)inputTensorAtIndex:(NSUInteger)index error:(NSError **)error;
/**
* Returns the output tensor at the given index.
*
* @param index The index of an output tensor.
* @param error An optional error parameter populated when there is an error in looking up the
* output tensor.
*
* @return The output tensor at the given index. `nil` if there is an error. See the `TFLTensor`
* class documentation for more details on the life expectancy between the returned tensor and
* this interpreter.
*/
- (nullable TFLTensor *)outputTensorAtIndex:(NSUInteger)index error:(NSError **)error;
/**
* Resizes the input tensor at the given index to the specified shape (an array of positive unsigned
* integers).
*
* @param index The index of an input tensor.
* @param shape Shape that the given input tensor should be resized to. It should be an array of
* positive unsigned integer(s) containing the size of each dimension.
* @param error An optional error parameter populated when there is an error in resizing the input
* tensor.
*
* @return Whether the input tensor was resized successfully. Returns NO if an error occurred.
*/
- (BOOL)resizeInputTensorAtIndex:(NSUInteger)index
toShape:(NSArray<NSNumber *> *)shape
error:(NSError **)error;
/**
* Allocates memory for tensors.
*
* @param error An optional error parameter populated when there is an error in allocating memory.
*
* @return Whether memory allocation is successful. Returns NO if an error occurred.
*/
- (BOOL)allocateTensorsWithError:(NSError **)error;
/**
* Returns a new signature runner instance for the signature with the given key in the model.
*
* @param key The signature key.
* @param error An optional error parameter populated when there is an error creating the signature
* runner.
*
* @return A new signature runner instance for the signature with given key.
*/
- (nullable TFLSignatureRunner *)signatureRunnerWithKey:(NSString *)key error:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,58 @@
// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/** Custom configuration options for a TensorFlow Lite interpreter. */
@interface TFLInterpreterOptions : NSObject
/**
* Maximum number of threads that the interpreter should run on. Defaults to 0 (unspecified, letting
* TensorFlow Lite to optimize the threading decision).
*/
@property(nonatomic) NSUInteger numberOfThreads;
/**
* Experimental: Enable an optimized set of floating point CPU kernels (provided by XNNPACK).
*
* Enabling this flag will enable use of a new, highly optimized set of CPU kernels provided via the
* XNNPACK delegate. Currently, this is restricted to a subset of floating point operations.
* Eventually, we plan to enable this by default, as it can provide significant performance benefits
* for many classes of floating point models. See
* https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/xnnpack/README.md
* for more details.
*
* Things to keep in mind when enabling this flag:
*
* * Startup time and resize time may increase.
* * Baseline memory consumption may increase.
* * Compatibility with other delegates (e.g., GPU) has not been fully validated.
* * Quantized models will not see any benefit.
*
* WARNING: This is an experimental interface that is subject to change.
*/
@property(nonatomic) BOOL useXNNPACK;
/**
* Initializes a new instance of `TFLInterpreterOptions`.
*
* @return A new instance of `TFLInterpreterOptions`.
*/
- (instancetype)init NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,91 @@
// Copyright 2020 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "TFLDelegate.h"
NS_ASSUME_NONNULL_BEGIN
/**
* @enum TFLMetalDelegateThreadWaitType
* This enum specifies wait type for Metal delegate.
*/
typedef NS_ENUM(NSUInteger, TFLMetalDelegateThreadWaitType) {
/**
* The thread does not wait for the work to complete. Useful when the output of the work is used
* with the GPU pipeline.
*/
TFLMetalDelegateThreadWaitTypeDoNotWait,
/** The thread waits until the work is complete. */
TFLMetalDelegateThreadWaitTypePassive,
/**
* The thread waits for the work to complete with minimal latency, which may require additional
* CPU resources.
*/
TFLMetalDelegateThreadWaitTypeActive,
/** The thread waits for the work while trying to prevent the GPU from going into sleep mode. */
TFLMetalDelegateThreadWaitTypeAggressive,
};
/** Custom configuration options for a Metal delegate. */
@interface TFLMetalDelegateOptions : NSObject
/**
* Indicates whether the GPU delegate allows precision loss, such as allowing `Float16` precision
* for a `Float32` computation. The default is `false`.
*/
@property(nonatomic, getter=isPrecisionLossAllowed) BOOL precisionLossAllowed;
/**
* Indicates how the current thread should wait for work on the GPU to complete. The default
* is `TFLMetalDelegateThreadWaitTypePassive`.
*/
@property(nonatomic) TFLMetalDelegateThreadWaitType waitType;
/**
* Indicates whether the GPU delegate allows execution of an 8-bit quantized model. The default is
* `true`.
*/
@property(nonatomic, getter=isQuantizationEnabled) BOOL quantizationEnabled;
@end
/**
* A delegate that uses the `Metal` framework for performing TensorFlow Lite graph operations with
* GPU acceleration.
*/
@interface TFLMetalDelegate : TFLDelegate
/**
* Initializes a new GPU delegate with default options.
*
* @return A new GPU delegate with default options. `nil` when the GPU delegate creation fails.
*/
- (nullable instancetype)init;
/**
* Initializes a new GPU delegate with the given options.
*
* @param options GPU delegate options.
*
* @return A new GPU delegate with default options. `nil` when the GPU delegate creation fails.
*/
- (nullable instancetype)initWithOptions:(TFLMetalDelegateOptions *)options
NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,36 @@
// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Parameters for asymmetric quantization. Quantized values can be converted to float values using:
* `realValue = scale * (quantizedValue - zeroPoint)`.
*/
@interface TFLQuantizationParameters : NSObject
/** Scale of asymmetric quantization. */
@property(nonatomic, readonly) float scale;
/** Zero point of asymmetric quantization. */
@property(nonatomic, readonly) int32_t zeroPoint;
/** Unavailable. */
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,154 @@
// Copyright 2022 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFLTensor;
/** Domain for errors in the signature runner API. */
FOUNDATION_EXPORT NSErrorDomain const TFLSignatureRunnerErrorDomain;
/**
* @enum TFLSignatureRunnerErrorCode
* This enum specifies various error codes related to `TFLSignatureRunner`.
*/
typedef NS_ENUM(NSUInteger, TFLSignatureRunnerErrorCode) {
/** Input data has invalid byte size. */
TFLSignatureRunnerErrorCodeInvalidInputByteSize,
/** Provided shape is invalid. It must be a non-empty array of positive unsigned integers. */
TFLSignatureRunnerErrorCodeInvalidShape,
/** Failed to create `TFLSignatureRunner`. */
TFLSignatureRunnerErrorCodeFailedToCreateSignatureRunner,
/** Failed to invoke `TFLSignatureRunner`. */
TFLSignatureRunnerErrorCodeFailedToInvoke,
/** Failed to retrieve a tensor. */
TFLSignatureRunnerErrorCodeFailedToGetTensor,
/** Invalid tensor. */
TFLSignatureRunnerErrorCodeInvalidTensor,
/** Failed to resize an input tensor. */
TFLSignatureRunnerErrorCodeFailedToResizeInputTensor,
/** Failed to copy data into an input tensor. */
TFLSignatureRunnerErrorCodeFailedToCopyDataToInputTensor,
/** Copying data into an output tensor not allowed. */
TFLSignatureRunnerErrorCodeCopyDataToOutputTensorNotAllowed,
/** Failed to get data from a tensor. */
TFLSignatureRunnerErrorCodeFailedToGetDataFromTensor,
/** Failed to allocate memory for tensors. */
TFLSignatureRunnerErrorCodeFailedToAllocateTensors,
};
/**
* A TensorFlow Lite model signature runner. You can get a `TFLSignatureRunner` instance for a
* signature from the `TFLInterpreter` and then use the SignatureRunner APIs.
*
* @note `TFLSignatureRunner` instances are *not* thread-safe.
* @note Each `TFLSignatureRunner` instance is associated with a `TFLInterpreter` instance. As long
* as a `TFLSignatureRunner` instance is still in use, its associated `TFLInterpreter` instance
* will not be deallocated.
*/
@interface TFLSignatureRunner : NSObject
/** The signature key. */
@property(nonatomic, readonly) NSString *signatureKey;
/** An ordered list of the SignatureDefs input names. */
@property(nonatomic, readonly) NSArray<NSString *> *inputs;
/** An ordered list of the SignatureDefs output names. */
@property(nonatomic, readonly) NSArray<NSString *> *outputs;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
/**
* Returns the input tensor with the given input name in the signature.
*
* @param name The input name in the signature.
* @param error An optional error parameter populated when there is an error in looking up the input
* tensor.
*
* @return The input tensor with the given input name. `nil` if there is an error. See the
* `TFLTensor` class documentation for more details on the life expectancy between the returned
* tensor and this signature runner.
*/
- (nullable TFLTensor *)inputTensorWithName:(NSString *)name error:(NSError **)error;
/**
* Returns the output tensor with the given output name in the signature.
*
* @param name The output name in the signature.
* @param error An optional error parameter populated when there is an error in looking up the
* output tensor.
*
* @return The output tensor with the given output name. `nil` if there is an error. See the
* `TFLTensor` class documentation for more details on the life expectancy between the returned
* tensor and this signature runner.
*/
- (nullable TFLTensor *)outputTensorWithName:(NSString *)name error:(NSError **)error;
/**
* Resizes the input tensor with the given input name to the specified shape (an array of positive
* unsigned integers).
*
* @param name The input name.
* @param shape Shape that the given input tensor should be resized to. It should be an array of
* positive unsigned integer(s) containing the size of each dimension.
* @param error An optional error parameter populated when there is an error in resizing the input
* tensor.
*
* @return Whether the input tensor was resized successfully. Returns NO if an error occurred.
*/
- (BOOL)resizeInputTensorWithName:(NSString *)name
toShape:(NSArray<NSNumber *> *)shape
error:(NSError **)error;
/**
* Allocates memory for tensors.
*
* @note This call is *purely optional*. Tensor allocation will occur automatically during
* execution.
*
* @param error An optional error parameter populated when there is an error in allocating memory.
*
* @return Whether memory allocation is successful. Returns NO if an error occurred.
*/
- (BOOL)allocateTensorsWithError:(NSError **)error;
/**
* Invoke the signature with given input data.
*
* @param inputs A map from input name to the input data. The input data will be copied into the
* input tensor.
* @param error An optional error parameter populated when there is an error in invoking the
* signature.
*
* @return Whether the invocation is successful. Returns NO if an error occurred.
*/
- (BOOL)invokeWithInputs:(NSDictionary<NSString *, NSData *> *)inputs Error:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
+121
View File
@@ -0,0 +1,121 @@
// Copyright 2018 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
@class TFLQuantizationParameters;
NS_ASSUME_NONNULL_BEGIN
/**
* @enum TFLTensorDataType
* This enum specifies supported TensorFlow Lite tensor data types.
*/
typedef NS_ENUM(NSUInteger, TFLTensorDataType) {
/** Tensor data type not available. This indicates an error with the model. */
TFLTensorDataTypeNoType,
/** 32-bit single precision floating point. */
TFLTensorDataTypeFloat32,
/** 16-bit half precision floating point. */
TFLTensorDataTypeFloat16,
/** 32-bit signed integer. */
TFLTensorDataTypeInt32,
/** 8-bit unsigned integer. */
TFLTensorDataTypeUInt8,
/** 64-bit signed integer. */
TFLTensorDataTypeInt64,
/** Boolean. */
TFLTensorDataTypeBool,
/** 16-bit signed integer. */
TFLTensorDataTypeInt16,
/** 8-bit signed integer. */
TFLTensorDataTypeInt8,
/** 64-bit double precision floating point. */
TFLTensorDataTypeFloat64,
/** 16-bit bfloat16 floating point. */
TFLTensorDataTypeBFloat16,
};
/**
* An input or output tensor in a TensorFlow Lite model.
*
* @warning Each `TFLTensor` instance is associated with its provider, either a `TFLInterpreter` or
* a `TFLSignatureRunner` instance. Multiple `TFLTensor` instances of the same TensorFlow Lite model
* are associated with the same provider instance. As long as a `TFLTensor` instance is still in
* use, its associated provider instance will not be deallocated.
*/
@interface TFLTensor : NSObject
/** Name of the tensor. */
@property(nonatomic, readonly, copy) NSString *name;
/** Data type of the tensor. */
@property(nonatomic, readonly) TFLTensorDataType dataType;
/** Parameters for asymmetric quantization. `nil` if the tensor does not use quantization. */
@property(nonatomic, readonly, nullable) TFLQuantizationParameters *quantizationParameters;
/** Unavailable. */
- (instancetype)init NS_UNAVAILABLE;
/**
* Copies the given data into an input tensor. This is allowed only for an input tensor and only
* before the interpreter or the signature runner is invoked; otherwise an error will be returned.
*
* @param data The data to set. The byte size of the data must match what's required by the input
* tensor.
* @param error An optional error parameter populated when there is an error in copying the data.
*
* @return Whether the data was copied into the input tensor successfully. Returns NO if an error
* occurred.
*/
- (BOOL)copyData:(NSData *)data error:(NSError **)error;
/**
* Retrieves a copy of data in the tensor. For an output tensor, the data is only available after
* the interpreter or signature runner invocation has successfully completed; otherwise an error
* will be returned.
*
* @param error An optional error parameter populated when there is an error in retrieving the data.
*
* @return A copy of data in the tensor. `nil` if there is an error in retrieving the data or the
* data is not available.
*/
- (nullable NSData *)dataWithError:(NSError **)error;
/**
* Retrieves the shape of the tensor, an array of positive unsigned integers containing the size
* of each dimension. For example: the shape of [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]] is
* [2, 2, 3] (i.e. an array of 2 arrays of 2 arrays of 3 numbers).
*
* @param error An optional error parameter populated when there is an error in retrieving the
* shape.
*
* @return The shape of the tensor. `nil` if there is an error in retrieving the shape.
*/
- (nullable NSArray<NSNumber *> *)shapeWithError:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
// Copyright 2019 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "TFLDelegate.h"
#import "TFLInterpreter.h"
#import "TFLInterpreterOptions.h"
#import "TFLQuantizationParameters.h"
#import "TFLSignatureRunner.h"
#import "TFLTensor.h"
NS_ASSUME_NONNULL_BEGIN
/**
* A string describing the semantic versioning information for the TensorFlow Lite runtime. Is an
* empty string if the version could not be determined.
*/
FOUNDATION_EXPORT NSString *const TFLVersion;
NS_ASSUME_NONNULL_END