Skip to content

Conversation

Tim-Siu
Copy link
Contributor

@Tim-Siu Tim-Siu commented Feb 26, 2024

Issues

Resolve #239

Running the quantization script quantize-ort.py cannot reproduce the quantized model in the repo. The current script will produce int8 quantized ppresnet50 at a size of over 120 MB, which is significantly different from the existing quantized models in the repo at the size of ~26 MB. After some investigation, I think the reason might be that preprocessing is missing. The ONNX documentation seems to suggest preprocessing is highly encouraged.

Left: Computation graph of already quantized models in the repo or models quantized by the updated script.
Right: Computation graph of the model quantized by the original script.

Screenshot 2024-02-26 at 23 15 36

We can see that the current script will result in a model with an unoptimized computation graph and redundant computation nodes.

Key Changes

  • A preprocessing step is added in quantize-ort.py. Optimization is automatically carried out by the quant_pre_process method.

Expected Benefits

  • Running the updated script should allow us to reproduce the quantized models already in the repo.

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Feb 26, 2024

By the way, I am very interested in working on the "Quantized models for OpenCV Model Zoo" project as part of Google Summer of Code. I am looking forward to any opportunities to contribute to opencv_zoo :)

@fengyuentau fengyuentau self-requested a review February 27, 2024 06:14
@fengyuentau fengyuentau self-assigned this Feb 27, 2024
@fengyuentau fengyuentau added the quantization Anything related to model quantization label Feb 27, 2024
@fengyuentau fengyuentau added this to the 4.10.0 milestone Feb 27, 2024
Copy link
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

@fengyuentau fengyuentau merged commit bdd60c2 into opencv:main Feb 27, 2024
@fengyuentau
Copy link
Member

By the way, I am very interested in working on the "Quantized models for OpenCV Model Zoo" project as part of Google Summer of Code. I am looking forward to any opportunities to contribute to opencv_zoo :)

We will see whether we have such project in this year's GSoC. In the meantime, you are welcome to apply for other projects.

@fengyuentau
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
quantization Anything related to model quantization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

quantize-ort.py doesn't reproduce the quantized models in the repos
2 participants