[mob][photos] Only do tokenizer init in computer

This commit is contained in:
laurenspriem
2024-06-29 15:29:24 +05:30
parent 2299e69227
commit dcb90f9e59
2 changed files with 15 additions and 3 deletions

View File

@@ -55,7 +55,13 @@ class ONNX extends MLFramework {
@override
Future<void> loadTextModel(String path) async {
final startTime = DateTime.now();
await _computer.compute(_clipText.initTokenizer);
final String vocabPath = await _clipText.getVocab();
await _computer.compute(
_clipText.initTokenizer,
param: {
"vocabPath": vocabPath,
},
);
_textEncoderAddress = await _computer.compute(
_clipText.loadModel,
param: {

View File

@@ -13,10 +13,16 @@ class OnnxTextEncoder {
final _logger = Logger("OnnxTextEncoder");
final OnnxTextTokenizer _tokenizer = OnnxTextTokenizer();
// Do not run in an isolate since rootBundle can only be accessed in the main isolate
Future<void> initTokenizer() async {
Future<String> getVocab() async {
final File vocabFile =
await RemoteAssetsService.instance.getAsset(kVocabRemotePath);
return vocabFile.path;
}
// Do not run in an isolate since rootBundle can only be accessed in the main isolate
Future<void> initTokenizer(Map args) async {
final String path = args["vocabPath"];
final File vocabFile = File(path);
final String vocab = await vocabFile.readAsString();
await _tokenizer.init(vocab);
}