Open neryabCommitted opened 2 months ago
hey @neryabCommitted you can create a drop down menu.. by which you can switch to your model from model1.tflite
to model2.tflite
. if you'd say i will share a code snippet that allows you to switch between your models.
thank you, that can be helpful
thank you, that can be helpful
I had put all the models in the project_directory/assets/models/
folder and the labels in the project_directory/assets/labels.txt
file. The vision
object is an instance of the FlutterVision
class that I created to handle the detection tasks. The modelPath
is the path to the selected model from the dropdown menu and the modelPaths
is a list of available models. If you have any further questions, feel free to ask.
Dropdown Menu for Model Selection:
DropdownButton<String>(
value: selectedModel,
onChanged: (String? newValue) {
setState(() {
selectedModel = newValue!;
});
loadYoloModel(selectedModel);
},
items: modelPaths.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
List of Available Models:
final List<String> modelPaths = [
'best_float16.tflite',
'best_float32.tflite',
'best_full_integer_quant.tflite',
'best_int8.tflite',
'best_integer_quant.tflite',
];
Loading the Selected Model:
Future<void> loadYoloModel(String modelPath) async {
await vision.loadYoloModel(
labels: 'assets/labels.txt',
modelPath: 'assets/models/$modelPath',
modelVersion: "yolov8",
quantization: false,
numThreads: 2,
useGpu: true,
);
}
Passing the Selected Model Path to the Detection Widget:
Widget task(Options option) {
if (option == Options.imagev8) {
return YoloImageV8(vision: vision, modelPath: selectedModel);
}
return const Center(child: Text("Trieu Tasca"));
}
Using the Selected Model in the Detection Widget:
class YoloImageV8 extends StatefulWidget {
final FlutterVision vision;
final String modelPath;
const YoloImageV8({Key? key, required this.vision, required this.modelPath})
: super(key: key);
@override
State<YoloImageV8> createState() => _YoloImageV8State();
}
class _YoloImageV8State extends State<YoloImageV8> {
@override
void initState() {
super.initState();
loadYoloModel(widget.modelPath).then((value) {
setState(() {
yoloResults = [];
isLoaded = true;
});
});
}
Future<void> loadYoloModel(String modelPath) async {
await widget.vision.loadYoloModel(
labels: 'assets/labels.txt',
modelPath: 'assets/models/$modelPath',
modelVersion: "yolov8",
quantization: false,
numThreads: 2,
useGpu: true,
);
setState(() {
isLoaded = true;
});
}
}
Make sure the logs on the console shows you the positive result whenever you choose any model from the dropdown menu. It will be something like,
I/tflite (12680): Replacing 465 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 29 partitions.
I/tflite (12680): Replacing 211 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 145 partitions.
I/tflite (12680): Replacing 465 node(s) with delegate (TfLiteXNNPackDelegate) node, yielding 29 partitions.
hey, because of budget consideration I'm forced to run two yolo models at the same time (instead of training one that combines them).
it it possible with flutterVision?
from what i've seen for some reason it only inference the second model loaded