ModelCheckpoint class
Dart-side weight persistence for on-device training models.
Saves and restores model weights to disk using the get_weights and
set_weights signatures that training models expose. This is exported on
native platforms only and does not require the Flex delegate or any native
library beyond the base TFLite runtime.
Binary checkpoint format (.flwt)
[4B magic "FLWT"] [1B version] [4B tensor count N]
Per tensor:
[4B name length] [name UTF-8] [4B TfLiteType] [4B rank]
[rank*4B shape dims] [4B data byte count] [data bytes]
Example
final interpreter = Interpreter.fromFile(modelFile);
// Train...
final trainRunner = interpreter.getSignatureRunner('train');
for (int i = 0; i < 100; i++) {
trainRunner.run({'x': [[1.0]], 'y': [[2.0]]}, {'loss': Float32List(1)});
}
trainRunner.close();
// Save weights to disk
await ModelCheckpoint.save(interpreter, File('model.flwt'));
// Later, restore into a fresh interpreter
final fresh = Interpreter.fromFile(modelFile);
await ModelCheckpoint.restore(fresh, File('model.flwt'));
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
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
inspect(
File file) → Future< Map< String, List< >int> > - Returns a map of tensor name to shape for every tensor in a checkpoint file. Reads and parses the entire file, then discards the tensor data, retaining only names and shapes. Useful for debugging and validation.
-
restore(
Interpreter interpreter, File file) → Future< void> -
Restores model weights from
fileintointerpreter. -
save(
Interpreter interpreter, File file) → Future< void> -
Saves the current model weights to
file.