loadFromAssets method
Load a model from the app assets. Returns the path to the loaded model.
By default, this method will not reload an already loaded model, you can
change this behaviour using the forceReload flag.
Implementation
Future<String> loadFromAssets(
final String asset, {
final bool forceReload = false,
}) async {
final modelName = path.basenameWithoutExtension(asset);
if (!forceReload && await isModelAlreadyLoaded(modelName)) {
final modelPathValue = await modelPath(modelName);
log('Model already loaded to $modelPathValue', name: 'ModelLoader');
return modelPathValue;
}
final start = DateTime.now();
final bytes = await (assetBundle ?? rootBundle).load(asset);
final decompressionPath = await _extractModel(bytes.buffer.asUint8List());
final decompressedModelRoot = path.join(decompressionPath, modelName);
log(
'Model loaded to $decompressedModelRoot in '
'${DateTime.now().difference(start).inMilliseconds}ms',
name: 'ModelLoader',
);
return decompressedModelRoot;
}