[mob][photos] Only do tokenizer init in computer
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user