Skip to content

Commit

Permalink
Merge pull request #302 from asus4/upgrade-v2.11.1
Browse files Browse the repository at this point in the history
Upgrade TensorFlow Lite to v2.11.1
  • Loading branch information
asus4 committed May 14, 2023
2 parents 4bdb36e + 3c2c4f4 commit 1eba9fd
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 51 deletions.
6 changes: 3 additions & 3 deletions Packages/com.github.asus4.mediapipe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"license": "SEE LICENSE IN LICENSE",
"unity": "2019.3",
"unityRelease": "0f1",
"version": "2.10.0-p1",
"version": "2.11.1",
"type": "library",
"hideInEditor": false,
"dependencies": {
"com.github.asus4.tflite": "2.10.0-p1",
"com.github.asus4.tflite.common": "2.10.0-p1"
"com.github.asus4.tflite": "2.11.1",
"com.github.asus4.tflite.common": "2.11.1"
}
}
4 changes: 2 additions & 2 deletions Packages/com.github.asus4.tflite.common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"license": "SEE LICENSE IN LICENSE",
"unity": "2019.3",
"unityRelease": "0f1",
"version": "2.10.0-p1",
"version": "2.11.1",
"type": "library",
"hideInEditor": false,
"dependencies": {
"com.github.asus4.tflite": "2.10.0-p1"
"com.github.asus4.tflite": "2.11.1"
}
}
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ typedef enum {
kTfLiteBuiltinUnsortedSegmentMax = 154,
kTfLiteBuiltinUnsortedSegmentSum = 155,
kTfLiteBuiltinAtan2 = 156,
kTfLiteBuiltinUnsortedSegmentMin = 157,
kTfLiteBuiltinSign = 158,
} TfLiteBuiltinOperator;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_C_C_API_H_
#define TENSORFLOW_LITE_C_C_API_H_
/// WARNING: Users of TensorFlow Lite should not include this file directly,
/// but should instead include "third_party/tensorflow/lite/c/c_api.h".
/// Only the TensorFlow Lite implementation itself should include this
/// file directly.
#ifndef TENSORFLOW_LITE_CORE_C_C_API_H_
#define TENSORFLOW_LITE_CORE_C_C_API_H_

#include <stdarg.h>
#include <stdint.h>
#include <stdlib.h>

#include "builtin_ops.h"
#include "c_api_types.h" // IWYU pragma: export

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -112,13 +117,19 @@ TFL_CAPI_EXPORT extern const char* TfLiteVersion(void);

// Returns a model from the provided buffer, or null on failure.
//
// NOTE: The caller retains ownership of the `model_data` and should ensure that
// the lifetime of the `model_data` must be at least as long as the lifetime
// of the `TfLiteModel`.
// NOTE: The caller retains ownership of the `model_data` buffer and should
// ensure that the lifetime of the `model_data` buffer must be at least as long
// as the lifetime of the `TfLiteModel` and of any `TfLiteInterpreter` objects
// created from that `TfLiteModel`, and furthermore the contents of the
// `model_data` buffer must not be modified during that time."
TFL_CAPI_EXPORT extern TfLiteModel* TfLiteModelCreate(const void* model_data,
size_t model_size);

// Returns a model from the provided file, or null on failure.
//
// NOTE: The file's contents must not be modified during the lifetime of the
// `TfLiteModel` or of any `TfLiteInterpreter` objects created from that
// `TfLiteModel`.
TFL_CAPI_EXPORT extern TfLiteModel* TfLiteModelCreateFromFile(
const char* model_path);

Expand All @@ -132,13 +143,42 @@ TFL_CAPI_EXPORT extern void TfLiteModelDelete(TfLiteModel* model);
// the lifetime of the `TfLiteInterpreter`.
// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern TfLiteRegistrationExternal*
TfLiteRegistrationExternalCreate(const char* custom_name, const int version);
TfLiteRegistrationExternalCreate(TfLiteBuiltinOperator builtin_code,
const char* custom_name, int version);

// Return the builtin op code of the provided external 'registration'.
//
// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern TfLiteBuiltinOperator
TfLiteRegistrationExternalGetBuiltInCode(
const TfLiteRegistrationExternal* registration);

// Destroys the TfLiteRegistrationExternal instance.
// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern void TfLiteRegistrationExternalDelete(
TfLiteRegistrationExternal* registration);

// Sets the initialization callback for the registration.
//
// The callback is called to initialize the op from serialized data.
// Please refer `init` of `TfLiteRegistration` for the detail.
// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern void TfLiteRegistrationExternalSetInit(
TfLiteRegistrationExternal* registration,
void* (*init)(TfLiteOpaqueContext* context, const char* buffer,
size_t length));

// Sets the deallocation callback for the registration.
//
// This callback is called to deallocate the data returned by the init callback.
// The value passed in the `data` parameter is the value that was returned by
// the `init` callback.
// Please refer `free` of `TfLiteRegistration` for the detail.
// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern void TfLiteRegistrationExternalSetFree(
TfLiteRegistrationExternal* registration,
void (*free)(TfLiteOpaqueContext* context, void* data));

// Sets the preparation callback for the registration.
//
// The callback is called when the inputs of operator have been resized.
Expand Down Expand Up @@ -181,6 +221,17 @@ TFL_CAPI_EXPORT extern void TfLiteInterpreterOptionsSetNumThreads(
TFL_CAPI_EXPORT extern void TfLiteInterpreterOptionsAddDelegate(
TfLiteInterpreterOptions* options, TfLiteDelegate* delegate);

// Adds an opaque delegate to be applied during `TfLiteInterpreter` creation.
//
// If delegate application fails, interpreter creation will also fail with an
// associated error logged.
//
// NOTE: The caller retains ownership of the delegate and should ensure that it
// remains valid for the duration of any created interpreter's lifetime.
TFL_CAPI_EXPORT extern void TfLiteInterpreterOptionsAddOpaqueDelegate(
TfLiteInterpreterOptions* options,
TfLiteOpaqueDelegateStruct* opaque_delegate);

// Sets a custom error reporter for interpreter execution.
//
// * `reporter` takes the provided `user_data` object, as well as a C-style
Expand Down Expand Up @@ -212,9 +263,17 @@ TFL_CAPI_EXPORT extern void TfLiteInterpreterOptionsAddRegistrationExternal(
// failure.
//
// * `model` must be a valid model instance. The caller retains ownership of the
// object, and the model must outlive the interpreter.
// object, and may destroy it (via TfLiteModelDelete) immediately after
// creating the interpreter. However, if the TfLiteModel was allocated with
// TfLiteModelCreate, then the `model_data` buffer that was passed to
// TfLiteModelCreate must outlive the lifetime of the TfLiteInterpreter object
// that this function returns, and must not be modified during that time;
// and if the TfLiteModel was allocated with TfLiteModelCreateFromFile, then
// the contents of the model file must not be modified during the lifetime of
// the TfLiteInterpreter object that this function returns.
// * `optional_options` may be null. The caller retains ownership of the object,
// and can safely destroy it immediately after creating the interpreter.
// and can safely destroy it (via TfLiteInterpreterOptionsDelete) immediately
// after creating the interpreter.
//
// NOTE: The client *must* explicitly allocate tensors before attempting to
// access input tensor data or invoke the interpreter.
Expand Down Expand Up @@ -357,4 +416,4 @@ TFL_CAPI_EXPORT extern TfLiteStatus TfLiteTensorCopyToBuffer(
} // extern "C"
#endif // __cplusplus

#endif // TENSORFLOW_LITE_C_C_API_H_
#endif // TENSORFLOW_LITE_CORE_C_C_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ typedef enum TfLiteStatus {
// resolved at runtime. This could happen when the specific op is not
// registered or built with the TF Lite framework.
kTfLiteUnresolvedOps = 7,

// Generally referring to invocation cancelled by the user.
// See `interpreter::Cancel`.
// TODO(b/194915839): Implement `interpreter::Cancel`.
// TODO(b/250636993): Cancellation triggered by `SetCancellationFunction`
// should also return this status code.
kTfLiteCancelled = 8,
} TfLiteStatus;

// Types supported by tensor
Expand All @@ -99,6 +106,7 @@ typedef enum {
kTfLiteVariant = 15,
kTfLiteUInt32 = 16,
kTfLiteUInt16 = 17,
kTfLiteInt4 = 18,
} TfLiteType;

// Legacy. Will be deprecated in favor of TfLiteAffineQuantization.
Expand All @@ -124,6 +132,15 @@ typedef struct TfLiteOpaqueNode TfLiteOpaqueNode;
// TfLiteOpaqueTensor is an opaque version of TfLiteTensor;
typedef struct TfLiteOpaqueTensor TfLiteOpaqueTensor;

// TfLiteOpaqueDelegateStruct: opaque version of TfLiteDelegate; allows
// delegation of nodes to alternative backends.
//
// This is an abstract type that is intended to have the same
// role as TfLiteDelegate from common.h, but without exposing the implementation
// details of how delegates are implemented.
// WARNING: This is an experimental type and subject to change.
typedef struct TfLiteOpaqueDelegateStruct TfLiteOpaqueDelegateStruct;

#ifdef __cplusplus
} // extern C
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ typedef enum TfLiteExternalContextType {
struct TfLiteContext;
struct TfLiteDelegate;
struct TfLiteRegistration;
struct TfLiteOpaqueDelegateStruct;
struct TfLiteOpaqueDelegateBuilder;

// An external context is a collection of information unrelated to the TF Lite
// framework, but useful to a subset of the ops. TF Lite knows very little
Expand Down Expand Up @@ -639,8 +641,23 @@ void TfLiteTensorReset(TfLiteType type, const char* name, TfLiteIntArray* dims,
// quantization, sparsity, ...
TfLiteStatus TfLiteTensorCopy(const TfLiteTensor* src, TfLiteTensor* dst);

// Resize the allocated data of a (dynamic) tensor. Tensors with allocation
// types other than kTfLiteDynamic will be ignored.
// Change the size of the memory block owned by `tensor` to `num_bytes`.
// Tensors with allocation types other than kTfLiteDynamic will be ignored.
// `tensor`'s internal data buffer will be assigned a pointer
// which can safely be passed to free or realloc if `num_bytes` is zero.
// Behaviour is undefined if `tensor` is NULL.
// If `preserve_data` is true, tensor data will be unchanged in the range from
// the start of the region up to the minimum of the old and new sizes.
void TfLiteTensorResizeMaybeCopy(size_t num_bytes, TfLiteTensor* tensor,
bool preserve_data);

// Change the size of the memory block owned by `tensor` to `num_bytes`.
// Tensors with allocation types other than kTfLiteDynamic will be ignored.
// `tensor`'s internal data buffer will be assigned a pointer
// which can safely be passed to free or realloc if `num_bytes` is zero.
// Behaviour is undefined if `tensor` is NULL.
// Tensor data will be unchanged in the range from the start of the region up to
// the minimum of the old and new sizes.
void TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor* tensor);
#endif // TF_LITE_STATIC_MEMORY

Expand Down Expand Up @@ -973,7 +990,7 @@ typedef enum TfLiteDelegateFlags {
typedef struct TfLiteDelegate {
// Data that delegate needs to identify itself. This data is owned by the
// delegate. The delegate is owned in the user code, so the delegate is
// responsible for doing this when it is destroyed.
// responsible for deallocating this when it is destroyed.
void* data_;

// Invoked by ModifyGraphWithDelegate. This prepare is called, giving the
Expand Down Expand Up @@ -1010,12 +1027,83 @@ typedef struct TfLiteDelegate {

// Bitmask flags. See the comments in `TfLiteDelegateFlags`.
int64_t flags;

// The opaque delegate builder associated with this object. If set then the
// TF Lite runtime will give precedence to this field. E.g. instead of
// invoking 'Prepare' via the function pointer inside the 'TfLiteDelegate'
// object, the runtime will first check if the corresponding function
// pointer inside 'opaque_delegate_builder' is set and if so invoke that.
//
// If this field is non-null, then the 'Prepare' field (of the
// 'TfLiteDelegate') should be null.
struct TfLiteOpaqueDelegateBuilder* opaque_delegate_builder;
} TfLiteDelegate;

// Build a 'null' delegate, with all the fields properly set to their default
// values.
TfLiteDelegate TfLiteDelegateCreate(void);

// `TfLiteOpaqueDelegateBuilder` is used for constructing
// `TfLiteOpaqueDelegateStruct`, see `TfLiteOpaqueDelegateCreate` below. Note:
// This struct is not ABI stable.
//
// For forward source compatibility `TfLiteOpaqueDelegateBuilder` objects should
// be brace-initialized, so that all fields (including any that might be added
// in the future) get zero-initialized. The purpose of each field is exactly
// the same as with `TfLiteDelegate`.
//
// WARNING: This is an experimental interface that is subject to change.
typedef struct TfLiteOpaqueDelegateBuilder {
// Data that delegate needs to identify itself. This data is owned by the
// delegate. The delegate is owned in the user code, so the delegate is
// responsible for deallocating this when it is destroyed.
void* data;
// Invoked by ModifyGraphWithDelegate. This prepare is called, giving the
// delegate a view of the current graph through TfLiteContext*. It typically
// will look at the nodes and call ReplaceNodeSubsetsWithDelegateKernels()
// to ask the TensorFlow lite runtime to create macro-nodes to represent
// delegated subgraphs of the original graph.
TfLiteStatus (*Prepare)(TfLiteOpaqueContext* context, // NOLINT
struct TfLiteOpaqueDelegateStruct* delegate,
void* data);
// Copies the data from delegate buffer handle into raw memory of the given
// 'tensor'. Note that the delegate is allowed to allocate the raw bytes as
// long as it follows the rules for kTfLiteDynamic tensors, in which case this
// cannot be null.
TfLiteStatus (*CopyFromBufferHandle)( // NOLINT
TfLiteOpaqueContext* context, struct TfLiteOpaqueDelegateStruct* delegate,
void* data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor* tensor);
// Copies the data from raw memory of the given 'tensor' to delegate buffer
// handle. This can be null if the delegate doesn't use its own buffer.
TfLiteStatus (*CopyToBufferHandle)( // NOLINT
TfLiteOpaqueContext* context, struct TfLiteOpaqueDelegateStruct* delegate,
void* data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor* tensor);
// Frees the Delegate Buffer Handle. Note: This only frees the handle, but
// this doesn't release the underlying resource (e.g. textures). The
// resources are either owned by application layer or the delegate.
// This can be null if the delegate doesn't use its own buffer.
void (*FreeBufferHandle)(TfLiteOpaqueContext* context, // NOLINT
struct TfLiteOpaqueDelegateStruct* delegate,
void* data, TfLiteBufferHandle* handle);
// Bitmask flags. See the comments in `TfLiteDelegateFlags`.
int64_t flags;
} TfLiteOpaqueDelegateBuilder;

// Creates an opaque delegate and returns its address. The opaque delegate will
// behave according to the provided 'opaque_delegate_builder'. The lifetime of
// the fields within the 'opaque_delegate_builder' must outlive any interaction
// between the runtime and the returned 'TfLiteOpaqueDelegateStruct'. The
// returned address should be passed to 'TfLiteOpaqueDelegateDelete' for
// deletion. If 'opaque_delegate_builder' is a null pointer, then a null
// pointer will be returned.
struct TfLiteOpaqueDelegateStruct* TfLiteOpaqueDelegateCreate(
const TfLiteOpaqueDelegateBuilder* opaque_delegate_builder);

// Deletes the provided opaque 'delegate'. This function has no effect if the
// 'delegate' is a null pointer.
void TfLiteOpaqueDelegateDelete(
const struct TfLiteOpaqueDelegateStruct* delegate);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
Git LFS file not shown
Git LFS file not shown
Loading

0 comments on commit 1eba9fd

Please sign in to comment.