I developed flutter app and yolov3
custom object detector. Both modules are independent. Now I want to combine those modules into a single project but could not figure out how to use that trained weights of that custom object detector in my flutter app. Could anyone please help me with this integration?
Asked
Active
Viewed 3,883 times
2

Boken
- 4,825
- 10
- 32
- 42

Sulav Panthi
- 21
- 1
- 2
-
2Welcome to stackoverflow =) Please add more details of what you want to achieve. Which languages are you using? Which framework? If you make your question more understandable it is easier for us to help you! https://stackoverflow.com/help/how-to-ask – Victor Zuanazzi Jul 18 '20 at 10:39
1 Answers
2
I don't know whether using Flutter
you're building android
app or iOS
.
Anyway to be able to use custom trained Yolov3
model on your Flutter
app, follow these two steps.
1. First you need to convert trained yolov3 model to tflite
version:
You can use this repo for that purpose.
Save custom trained Yolov3 darknet
weights to tfmodel
that's needed for tflite
conversion:
python save_model.py --weights yolov3.weights --output ./checkpoints/yolov3-416 --input_size 416 --model yolov3 --framework tflite
Convert Yolov3
model to tflite
version:
python convert_tflite.py --weights ./checkpoints/yolov3-416 --output ./checkpoints/yolov3-416.tflite
2. Then you use Flutter
plugin for accessing TensorFlow-Lite
API, which works with both android
and iOS
- https://github.com/shaqian/flutter_tflite
a) Create a assets folder and place your label file and model file in
it. In pubspec.yaml
add:
assets:
assets/labels.txt
assets/yolov3-416.tflite
b) Import the library:
import 'package:tflite/tflite.dart';
c) Load the model and labels:
String res = await Tflite.loadModel(
model: "assets/yolov3-416.tflite",
labels: "assets/labels.txt",
numThreads: 1, // defaults to 1
isAsset: true, // defaults to true, set to false to load resources outside assets
useGpuDelegate: false // defaults to false, set to true to use GPU delegate
);
d) To run on image:
var recognitions = await Tflite.detectObjectOnImage(
path: filepath, // required
model: "YOLOv3",
imageMean: 0.0,
imageStd: 255.0,
threshold: 0.3, // defaults to 0.1
numResultsPerClass: 2,// defaults to 5
anchors: anchors, // defaults to [0.57273,0.677385,1.87446,2.06253,3.33843,5.47434,7.88282,3.52778,9.77052,9.16828]
blockSize: 32, // defaults to 32
numBoxesPerBlock: 5, // defaults to 5
asynch: true // defaults to true
);
e) Release resources:
await Tflite.close();

Venkatesh Wadawadagi
- 2,793
- 21
- 34
-
-
@greenzebra Answer clearly suggests it's applicable for `Yolov3` only and also question was also about `Yolov3` – Venkatesh Wadawadagi Jan 18 '23 at 17:49
-
-
-
1I believe this package can be altered to work with YOLOv3. But I believe you would have to change the image processing. For reference, alterations to the package to work with YOLOv4: https://github.com/TexMexMax/object_detection_flutter – greenzebra Jan 18 '23 at 18:04
-
@greenzebra Yes I have used it with `Yolov3`. Earlier I misread your reply, I thought it didn't work for you when you used it with `Yolov2` that's why I responded accordingly. – Venkatesh Wadawadagi Jan 18 '23 at 18:17
-
You are right, If I can recall there was issue in getting `Yolov3` working as architecture was different from `Yolov2`. Eventually I got it working. – Venkatesh Wadawadagi Jan 18 '23 at 18:18
-
If you're still facing the issue request you to create a separate question with specific issue/error – Venkatesh Wadawadagi Jan 18 '23 at 18:19
-
1Ah I see. I got that package working with YOLOv4, however now I am using YOLOX with the following: https://pub.dev/packages/ncnn_yolox_flutter – greenzebra Jan 18 '23 at 18:24