restore static method
Restores model weights from file into interpreter.
The interpreter must have a set_weights signature. The file must be
a valid .flwt checkpoint created by save.
Implementation
static Future<void> restore(Interpreter interpreter, File file) async {
if (!interpreter.signatureKeys.contains('set_weights')) {
throw ArgumentError('Model does not have a "set_weights" signature.');
}
final bytes = await file.readAsBytes();
final records = _parseCheckpoint(bytes);
final runner = interpreter.getSignatureRunner('set_weights');
try {
final inputs = <String, Object>{};
for (final record in records) {
final tensorType = TensorType.fromValue(record.type);
inputs[record.name] = ByteConversionUtils.convertBytesToObject(
record.data,
tensorType,
record.shape,
);
}
runner.run(inputs, {});
} finally {
runner.close();
}
}