-
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
Fixed int8 quantization and added experimental mixed int8/int16 quantization #228
base: master
Are you sure you want to change the base?
Conversation
… available on PyPi
…m up with other examples that don't use --framework tflite Added gitignore
…ng EXPERIMENTAL_TFLITE_BUILTINS_ACTIVATIONS_INT16_WEIGHTS_INT8
Hello, thanks for the great work, will the above fixes be able to fully quantize the yolov4/v3 model in order for it to run at tpu? |
No, unfortunately it it doesn't fully quantize currently, since the network uses some non-quantizable ops (EXP). I've not looked further into that yet. When I try with
I get
|
@mikljohansson, running your patch set (pulling your forked repo) gives the following error in my environment
Since this depends on Note the below was also in the debug log, a good ways before the backtrace information
|
@raryanpur I think the problem might be perhaps that some file paths are incorrect in the calibration dataset (e.g. I've improved the error reporting for this now, if you pull and try again it might give you a better error message about what's wrong. If it turns out the dataset is missing there's instructions in the README.md about how to download it Best, |
Ah that did the trick - thanks @mikljohansson, works now! |
@mikljohansson when using this quantized model, how are the inputs and outputs scaled? My understanding is that the inputs are still floats, but the values must be scaled from [0.0, 255.0] to [-128.0, 127.0]. Do the outputs (score and box tensor values) need to be scaled as well? |
Hi @mikljohansson , thanks for your great work. After running your modification. I got my yolov3_int_8.tflite model work. And the message was shown below
My question is : Why does it say |
@raryanpur sorry for not getting back, E-mail got lost in my inbox :( I honestly don't know, sorry. I haven't dug into the input/output scaling and haven't worked on this model for a while (focusing on other things right now). Hopefully you've been able to work it out already :) |
Not sure honestly why that is. I could imagine it could be because the network doesn't quantize fully (due to the Perhaps you could try to uncomment these lines in
This flag might set all intermediate weights and calculations to 8-bit, but I don't think it'd work currently due to the inability to fully quantize the network
|
after converting a customized(not coco) yolov3-tiny into .tflite format python convert_tflite.py --weights ./checkpoints/yolov4-416 --output ./checkpoints/yolov4-416-int8.tflite --quantize_mode int8 --dataset ./coco_dataset/coco/val207.txt ./checkpoints/yolov4-416 ---> this is not coco model, it is from customized/different dataset
|
I also have the above error, @mikljohansson were you able to fix this ? if yes can you provide the solution. Thanks! |
Thanks for providing these examples of working with Yolo v4/v3!
I managed to fix the int8 quantization by adding a
model.compile()
statement to fix the "optimize global tensors" exception. I could also remove overridingsupported_ops
, by following the examples TensorFlow Lite provides for quantization.FYI: I'm currently trying to port these models to the K210 / MaixPy MCU, but so far haven't managed to get nncase fully consume the tflite files yet (it doesn't support the
SPLIT
andDEQUANTIZE
op tflite codes).Note: This only works on the latest
tf-nightly
(2.4.0+). It doesn't work on tensorflow-2.3.0It doesn't fully quantize currently, since the network uses some non-quantizable ops (EXP). I've not looked further into that yet.
Best regards,
Mikael