-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Quantizing ONNX-compliant model to Q7 for use with CMSIS-NN functions #963
Comments
To answer your questions
When you said 'forcing everything to be Q7', you implicitly considered the range of -128 to 127, which is an There are many other Q7 formats (Q3.4, Q1.6 ...). And yes, you need to compute them to see which is best fitting your data. However, you still can force all data to a fixed point, sometimes it sometimes can provide fair results in not-so-deep networks. |
@majianjia thanks, I think I understand a bit better now. A major source of my confusion was that I thought Q-format refers to 8 bit or 16 bit. But actually the Q-format includes the position of the decimal point as well. In this light it makes sense to "compute the Q-format" as we want to know where to put the decimal point. My next question is: Suppose I have a quantized layer, e.g. Conv. The activations and weights are quantized and the scale is a power of two for each. Then how do I convert this to a CMSIS-NN layer? If I use |
@dtch1997 If you search my id in the issues, there are other related topics that might help. A simple explanation is these 2 arguments are not stood by themself, but also stand for the relation between Detail: What you can see from here is we only use the decimal bits to do the calculation because in Q7, always have integer bits + decimal bit = 7. A convolutional or fully connected layer can be explained in For example, if you have data like these: For multiplication (Input*Weights), For addition (Bias), Both data must be converted to the same Q format to be added together. Per the 2 equations, for you to determine both arguments, you will need the Q format of all |
Okay I think I finally understood. The last source of my confusion is that CMSIS-NN quantization is different from other frameworks' quantization. In Tensorflow or PyTorch, values are quantized by choosing a "scale" and "zero point". In CMSIS-NN values are quantized by simply rounding the number to the nearest fixed-point number. @majianjia maybe this can be added to documentation somewhere. |
You may check the new part of CMSIS-NN, thoes file names ended with |
This is a question rather than an issue. I don't really know anything about quantization, need to use it for an embedded systems project. Would be happy to learn from more experienced folks.
I'm attempting to convert an ONNX model into equivalent CMSIS-NN C++ code. I'm following this tutorial: https://developer.arm.com/solutions/machine-learning-on-arm/developer-material/how-to-guides/converting-a-neural-network-for-arm-cortex-m-with-cmsis-nn/single-page
Right now I'm doing quantization. I used the quantization script at https://github.com/microsoft/onnxruntime/tree/master/onnxruntime/python/tools/quantization to quantize model into Q7 format. This converts a float32 weight into an int8 weight, and float32 scale and zero-point values which can be used to (approximately) reconstruct the original weights.
My questions are:
arm_convolve_HWC_q7_fast
), and if not, then why not?The text was updated successfully, but these errors were encountered: