ModelLoader class
Manages loading and caching of TFLite models for on-device inference.
Models can be loaded from Flutter assets or from raw bytes. Once loaded, interpreters are cached for reuse across validations.
final loader = ModelLoader();
final interpreter = await loader.load('assets/models/typo_detector.tflite');
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Closes all cached interpreters and clears the cache.
-
getModelInfo(
Interpreter interpreter) → ModelInfo - Returns info about a loaded model's input/output tensors.
-
isLoaded(
String key) → bool - Whether a model is currently cached.
-
loadFromAsset(
String assetPath, {int numThreads = 2, bool useGpuDelegate = false}) → Future< Interpreter> - Loads a TFLite model from a Flutter asset path.
-
loadFromBytes(
Uint8List modelBytes, {String? cacheKey, int numThreads = 2}) → Interpreter - Loads a TFLite model from raw bytes.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unload(
String key) → void - Closes a specific cached interpreter and removes it from cache.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited