-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Here is a solution on how tu run yolov4 tflite-int8 model #214
Comments
Were you able to fully compile the model for the edge TPU? I was only able to get 39 supported ops + 8 that will run on the CPU for Yolo v4 Tiny. |
@alexanderswerdlow I only tried this on cpu, don't know how it compatiable with TPU. |
@alexanderswerdlow |
@hhk7734 Yep. I’ll double check tomorrow but I’m almost positive. The only significant change I made was leakyRelu -> Relu. I was able to get it running on the edge TPU but it runs quite horribly, compared to even yolo v3 tiny. The performance is fine with ~20ms per frame but the accuracy is very poor. |
@alexanderswerdlow |
Can't share the tflite but happy to share my config. It's basically the stock config just without leakyRelu, 416x416, the right filter value, etc. Edit if you're curious, here's my edgetpu_compiler output:
|
@alexanderswerdlow using input_size=416, inference time is ~60ms. |
@alexanderswerdlow how did you manage to convert the yolo model? But if I try to convert it with I get
I thought that running convert_tflite.py with --quantize_mode int8 takes care of this so I don´t really get what I´m missing. |
@alexanderswerdlow @murdockhou I would like to know this too. I've been trying to convert the weights of YOLOv3 and v4 to tflite ( fully int 8 quantized ) using these helpful steps but I didn't get a result sadly. I get the exact same result as @ItsMeTheBee above. I am a beginner and I would like to use this for a project. Any guidance would be extremely appreciated |
Tel me plese, how to use this int8 model in Android\ios project? With float16 and float32 models run is ok. |
No idea. It does not compile if used at the coral compiler, as it needs quantization even though I already did it |
Okay a little something about that: I was able to compile the model after some modifications in core/common.py and convert_tflite.py In convert_tflite.py I tried using the old converter:
With this the edgetpu_compiler can convert 17 ops:
Now this was done for a tiny v3 model so it might not work for you, you can still give it a try though =) |
Wow great work there. Have you tested it in Coral? What are the FPS @ItsMeTheBee? EDIT: I tried following your steps, but adding this line |
HI @murdockhou Tensorflow Version:tensorflow-gpu=2.3.0 / 2.3.0rc0 (All test) |
Hey @w840401 , |
I naively thought it was caused by a OS problem~ |
I tried using the coco dataset to convert to tflite, but I had empty min/max tensors. I really want to know how you got this to work @murdockhou . If as I said I omit the converter.representative_dataset = representative_data_gen line, I fail to quantize the model. The script runs, but if I compile with the coral model compiler, an error pops up saying The model is not quantized. Also, if I try to run the deepsort using this model, no bounding boxes are produced, which is weird. Could you help? |
我成功解決您說的此問題,是因為val2017.txt 路徑問題 你重新執行coco_dataset 路徑對,應該就沒問題了 |
Hey @w840401 , RuntimeError: Max and min for dynamic tensors should be recorded during calibration: Failed for tensor StatefulPartitionedCall/functional_1/zero_padding2d/Pad Any ideas? My val2017.txt is at the same folder as the pictures, and points to them. For example 000000000139.jpg ..... for this specific picture. Thanks for the help |
@JimBratsos I don't think need at the same folder as the pictures Quantification still has problems after this My english is poor~ Sorry |
When using the yolov4-tiny-int8 version, and run the model with
I got this error too.
Then, I added additional code in
Although the yolov4-tiny-int8 model is successfully detected, it runs slowly, takes about 300ms for each image on CPU. Does anyone have suggestions about this? |
@deep-rooteddz Thanks for sharing. I follow your step to modify my detect.py file and run, but the results went wrongs. It didn't get the similar results as the @murdockhou. Would you mind to show your inference results on kit.jpg? tks. |
@zero90169 If you don’t get the similar result, check config.py to confirm
And you may need to modify YOLO.ANCHORS_TINY to make it the same size as yolov4-tiny.weight(But not necessary, it will affect boundingbox size). e.g.
|
@deep-rooteddz Thanks for your kindly and quickly reply. I expected to get as many boxes as the kite.jpg which is shown by @murdockhou but my int8.tflite inference result on kite.jpg is more similar to yours. Maybe it is caused by "yolov4" and "yolov4-tiny". I will try the @hunglc007 's code again! |
@deep-rooteddz Thanks. Your solution works for me, like you I experience significant slowness in relation to FP32, it is around 300MS instead of 100MS inference time, have you been able to resolve this? I use tiny yolo v4 |
thanks, it works in my raspi 4, but why the int 8 model run slower than fp16 or 32?? I still not using any accelerator, full cpu. |
did anyone solve this issue?
and also not working in android app too (fp16 converted model works though) when I tested with int8 converted model, this error message is shown
|
Thanks, it works ! |
@murdockhou @deep-rooteddz @mipsan |
Have you solved it? I have encountered the same problem. Looking forward to your reply, thanks! |
I'm also having problems trying to convert a YOLOv4 model to full int8 quantization, and I don't have an answer yet but I found a bug in the convert_tflite.py script that will always result in a model that is not fully int8 quantized. The lines:
The second assignment to converter.target_spec.supported_ops supersedes the first that contains the int8 flag |
The reason is that you should add the post processing after invoking the model, since this was deleted from save_model.py script. |
Hello, I have tried to run the int8 model on the raspberry pi4. I got this error :
EDIT: The same with float 16 |
Hello, |
Hello, While running this I'm getting the following error [{'name': 'input_1', 'index': 0, 'shape': array([ 1, 416, 416, 3], dtype=int32), 'shape_signature': array([ -1, 416, 416, 3], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}] Can you please comment how to solve this error. |
Hi, thanks for your nicely work. As you say,
Yolov4 and Yolov4-tiny int8 quantization have some issues. I will try to fix that.
I have a solution to fix this, and below is the code:First, when
Convert darknet weights to tensorflow
, we should not containpost process
insaved_model
:Then, run this command line convert this to
tflite-int8
:I disable this param
--dataset ./coco_dataset/coco/val207.txt
since I do not have a coco dataset, also, you should to comment line 43Finally, add some code in
detect.py
(actually they arepose process
code we comment in the first step):run
python detect.py --weights ./checkpoints/yolov4-416-int8.tflite --size 416 --model yolov4 --image ./data/kite.jpg --framework tflite
and we will get this result like this:Hope that can help you.
The text was updated successfully, but these errors were encountered: