'how can i use more than one tflite flutter model?
i created one tflite model. i want to pass string to model and label according to user selection. for example, if your select model1 it will load model two, if user select model 2 it load model 2. in this scnerio, I don't want to create 2 models, I just want to change model and label string on runtime using if else condition. i am unable to wet set condition, can anyone guide me where can i set if condition?
loadModel() async {
await Tflite.loadModel(
model: "model location here",
labels: "label location here",
numThreads: 1,
);
}
Solution 1:[1]
I did it with a value listenable builder. When state.value
change, different model is loaded and it works.
if (state.value == 1) {
await Tflite.loadModel(
model: "assets/tflite_models/model_1.tflite",
labels: "assets/tflite_models/labels_1.txt");
} else if (state.value == 2) {
await Tflite.loadModel(
model: "assets/tflite_models/model_2.tflite",
labels: "assets/tflite_models/labels_2.txt");
} else {
await Tflite.loadModel(
model: "assets/tflite_models/model_3.tflite",
labels: "assets/tflite_models/labels_3.txt");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |