flutter_litert_flex

Platform Pub Version License

FlexDelegate (SELECT_TF_OPS) addon for flutter_litert. Automatically downloads and bundles the TensorFlow Lite Flex delegate native library at build time for all platforms.

When do you need this?

The Flex delegate is required when your .tflite model uses TensorFlow ops that aren't available as TFLite builtins. Common cases:

  • On-device training with convolutional or batch-normalized layers (gradient ops like Conv2DBackpropFilter)
  • Checkpoint-based persistence using tf.raw_ops.Save/Restore
  • Models converted with SELECT_TF_OPS enabled

If your model only uses TFLITE_BUILTINS, you don't need this package.

Installation

dependencies:
  flutter_litert: ^1.0.3
  flutter_litert_flex: ^0.0.1

That's it. The native libraries are downloaded automatically on the first build.

Usage

import 'package:flutter_litert/flutter_litert.dart';

final options = InterpreterOptions();
options.addDelegate(FlexDelegate());
final interpreter = await Interpreter.fromAsset('model.tflite', options: options);

No FlexDelegate.download() call needed when using this package.

Platform details

Platform Library Size Mechanism
iOS TensorFlowLiteFlex.xcframework ~492 MB CocoaPods (static framework)
macOS libtensorflowlite_flex-mac.dylib ~123 MB CocoaPods (bundled resource)
Linux libtensorflowlite_flex-linux.so ~333 MB CMake download
Windows libtensorflowlite_flex-win.dll ~227 MB CMake download
Android tensorflow-lite-select-tf-ops auto Maven dependency

Libraries are downloaded once and cached in the plugin directory. Subsequent builds use the cached copy.

Credits

Based on TensorFlow Lite v2.20.0. See flutter_litert for the base inference library.

Libraries

flutter_litert_flex
FlexDelegate (SELECT_TF_OPS) addon for flutter_litert.