Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom model & dataset #8

Closed
larrywal-express opened this issue Jan 31, 2022 · 7 comments
Closed

Custom model & dataset #8

larrywal-express opened this issue Jan 31, 2022 · 7 comments

Comments

@larrywal-express
Copy link

Thanks for your good work. I have a customized model at two detection scale trained with four class.. How do I modify the code to fit the application? Moreso, how to set up --tfds_root for quantize.py?

@lp6m
Copy link
Owner

lp6m commented Feb 4, 2022

Q1: Does two detection scale means that scale of width and height is different?

If so, you will need to modify the resize part of the input image and the scale calculation of the output bounding box image.
The number of classes is also different, so the postprocess part also needs to be modified.

https://github.com/lp6m/yolov5s_android/blob/master/app/tflite_yolov5_test/app/src/main/cpp/postprocess.cpp#L18

Q2: tfds_root in quantize.py
In general, tensorflow quantization process needs sample input data.
Instead of preparing a sample image in tfds format, you can modify representative_dataset_gen to return a custom training data image.
https://github.com/lp6m/yolov5s_android/blob/master/convert_model/quantize.py#L16-L25

@lp6m
Copy link
Owner

lp6m commented Feb 4, 2022

There are no plans to support models with different height and width sizes in this repository, but the forked project seems to be making an attempt to do so. (I have not tested this.)
rjean@a0eab90

@larrywal-express
Copy link
Author

@Ip6m I mean two detection scale for anchors. I have just 6 anchors instead of the 9 anchors.

@lp6m
Copy link
Owner

lp6m commented Feb 7, 2022

If the number of anchors is different from original model, you need to modify postprocess.cpp in this repository.

https://github.com/lp6m/yolov5s_android/blob/master/app/tflite_yolov5_test/app/src/main/cpp/postprocess.cpp

As described also in app/README.md, The algorithm of postprocess.cpp is equivalent to Detect layer of original yolov5 repositor. However, some variables are embedded as constants. It is possible to deal with this by making some modifications.
https://github.com/ultralytics/yolov5/blob/3e7c59ad3bf5414d4b2a26e018f397e27a51c6f1/models/yolo.py#L48-L68

@apanand14
Copy link

Hello @lp6m @larrywal-express ,

I have trained yolov5s on custom dataset (classes 2) and converted model to tflite-16fp. I also verified inference using detect.py and loading tflite model. it works fine locally. But when i use that model in your android app then, it doesn't give any error but also it doesn't draw any bounding box or do any detection. Can you please let me know what exactly I'm doing wrong in running custom tflite model in your app?? Your help will be appreciated.

Thank you in advance!!

@lp6m
Copy link
Owner

lp6m commented Jun 24, 2022

I write the tutorial for custom model & dataset. please check.
#14

@lp6m lp6m closed this as completed Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants