Answers.Body: <p>I have found the answer to this doubt I had. Here, 0.007709330413490534 = 1 / S, q = input, Z = 3. Basically, this is the formula to quantize the input value. If you pull out 1/S then it becomes clear. Here, is an <a href="https://towardsdatascience.com/inside-quantization-aware-training-4f91c8837ead" rel="nofollow noreferrer">article</a> related to this topic.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-08T15:39:10.180Z
Answers.Text: are you sure about 0.007709330413490534 = 1 / S ? It means S = 1 / 0.007709330413490534 ? I don't understand it
Answers.UserDisplayName: ThoG_Sor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-05T20:21:02.090Z
Answers.LastActivityDate: 2022-01-05T20:21:02.090Z
Answers.UserDisplayName: Amit
Answers.Body: <p>The quantization formula is <code>real_value = scale * (int_value - zero_point)</code>.</p>
  <ul>
  <li>Scale is calculated as <code>(float_max - float_min) / (int_max - int_min)</code>.</li>
  <li>Zero point is calculated as <code>int_min - (float_min / scale)</code>.</li>
  </ul>
  <ul>
  <li><code>float_max</code> is the max value in the float number line.</li>
  <li><code>float_min</code> is the min value in the float number line.</li>
  <li><code>int_min</code> is the min value in the integer number line.</li>
  <li><code>int_max</code> is the max value in the integer number line.</li>
  </ul>
  <p><code>quantization: 0.007709330413490534 * (q + 3)</code> means integer value <code>q</code> is mapped to float value using the scale <code>0.007709330413490534</code> and zero point <code>-3</code>.</p>
  <p>The zero point is the offset that shifts the integer value and scale is the factor that scales this integer value to a float value. Confused? Please check <a href="https://ai.stackexchange.com/a/40339/30950">this answer</a> which explains the intuition.</p>
  <p>If you have any doubts, please feel free to ask.</p>
  <p>Cheers,</p>
  <p>Thomas.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-10T11:48:30.987Z
Answers.Text: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).
Answers.UserDisplayName: Community
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-07T16:43:59.647Z
Answers.LastActivityDate: 2023-05-07T16:43:59.647Z
Answers.UserDisplayName: mrtpk
Answers.Body: <p>The text right next to the formula provided in netron is actually quite misleading, as it's actually a dequantization equation. The correct formula for calculating the dequantized value is:</p>
  <p><span class="math-container">$$ \mathbf{d} = \text{scale} \cdot (\mathbf{q} - \text{zeropoint}) $$</span>
  Where:
  <span class="math-container">$$ \mathbf{d} - \text{dequantized value} $$</span>
  <span class="math-container">$$ \mathbf{q} - \text{quantized value} $$</span></p>
  <p>Given your example, one can deduce that:
  <span class="math-container">$$  \text{scale} \approx 0.0077 $$</span>
  <span class="math-container">$$ \text{zeropoint} = -3 $$</span></p>
  <p>If you actually want to quantize the input value:
  <span class="math-container">$$ \mathbf{q} =  \frac{\mathbf{d}}{\text{scale}} + \text{zeropoint}  $$</span></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-18T12:41:58.493Z
Answers.LastActivityDate: 2024-06-18T12:41:58.493Z
Answers.UserDisplayName: Mateusz Koza
Body: <p>I was checking tflite file in Netron. There I found the quantization formula in Netron as below:</p>
  <pre><code>quantization: 0.007709330413490534 * (q + 3)
  </code></pre>
  <p>I know the quantization formula is: quantized_value = (r/S + Z) Where, r = input, S = scale and Z = zero-point</p>
  <p>I have used quantization-aware training before converting the model to the TFLite model. I have uploaded the <a href="https://drive.google.com/file/d/1cBwUvIo532nLLS64a7d-Hr_a5yY9iL55/view?usp=sharing" rel="nofollow noreferrer">TFlite Model file</a> to <a href="https://netron.app/" rel="nofollow noreferrer">Netron App website</a> where I have found quantization as below image. Can anyone explain What do the q and 3 mean in Netron quantization?</p>
  <p><a href="https://i.sstatic.net/daxaN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/daxaN.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-04T09:37:42.100Z
Comments.Text: Hello. Can you 1. put your **specific** question in the title, and 2. provide the link to the source where you took that screenshot from?
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-04T13:23:41.687Z
Comments.Text: I have added the file and edited the title.
Comments.UserDisplayName: Amit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-04T13:44:17.163Z
Comments.Text: Thanks. You may also want to [format the equations with latex/mathjax to improve the readability](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference).
Comments.UserDisplayName: nbro
Tags: <machine-learning><tensorflow>
Title: Can anyone please explain TFLite quantization part found in Netron neural network viewer?
UserDisplayName: Amit
ThreadText: # Can anyone please explain TFLite quantization part found in Netron neural network viewer?
  
  (Asked by: username_0 on 2022-01-04)
  
  I was checking tflite file in Netron. There I found the quantization formula in Netron as below:
  
  ```
  quantization: 0.007709330413490534 * (q + 3)
  
  ```
  
  I know the quantization formula is: quantized\_value = (r/S + Z) Where, r = input, S = scale and Z = zero-point
  
  I have used quantization-aware training before converting the model to the TFLite model. I have uploaded the [TFlite Model file](https://drive.google.com/file/d/1cBwUvIo532nLLS64a7d-Hr_a5yY9iL55/view?usp=sharing) to [Netron App website](https://netron.app/) where I have found quantization as below image. Can anyone explain What do the q and 3 mean in Netron quantization?
  
  [![enter image description here](https://i.sstatic.net/daxaN.png)](https://i.sstatic.net/daxaN.png)
  
  **Tags:** machine-learning, tensorflow
  
  > **Comments:**
  > **username_1**: Hello. Can you 1. put your **specific** question in the title, and 2. provide the link to the source where you took that screenshot from?  
  > **username_0**: I have added the file and edited the title.  
  > **username_1**: Thanks. You may also want to [format the equations with latex/mathjax to improve the readability](https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference).  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2022-01-05. Score: 3
  
  I have found the answer to this doubt I had. Here, 0.007709330413490534 = 1 / S, q = input, Z = 3. Basically, this is the formula to quantize the input value. If you pull out 1/S then it becomes clear. Here, is an [article](https://towardsdatascience.com/inside-quantization-aware-training-4f91c8837ead) related to this topic.
  
  > **Comments:**
  > **username_2**: are you sure about 0.007709330413490534 = 1 / S ? It means S = 1 / 0.007709330413490534 ? I don't understand it  
  
  ---
  
  ### Answer by username_3 on 2023-05-07. Score: 1
  
  The quantization formula is `real_value = scale * (int_value - zero_point)`.
  
  * Scale is calculated as `(float_max - float_min) / (int_max - int_min)`.
  * Zero point is calculated as `int_min - (float_min / scale)`.
  
  * `float_max` is the max value in the float number line.
  * `float_min` is the min value in the float number line.
  * `int_min` is the min value in the integer number line.
  * `int_max` is the max value in the integer number line.
  
  `quantization: 0.007709330413490534 * (q + 3)` means integer value `q` is mapped to float value using the scale `0.007709330413490534` and zero point `-3`.
  
  The zero point is the offset that shifts the integer value and scale is the factor that scales this integer value to a float value. Confused? Please check [this answer](https://ai.stackexchange.com/a/40339/30950) which explains the intuition.
  
  If you have any doubts, please feel free to ask.
  
  Cheers,
  
  Thomas.
  
  > **Comments:**
  > **username_4**: As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer).  
  
  ---
  
  ### Answer by username_5 on 2024-06-18. Score: 0
  
  The text right next to the formula provided in netron is actually quite misleading, as it's actually a dequantization equation. The correct formula for calculating the dequantized value is:
  
  $$ \mathbf{d} = \text{scale} \cdot (\mathbf{q} - \text{zeropoint}) $$
  Where:
  $$ \mathbf{d} - \text{dequantized value} $$
  $$ \mathbf{q} - \text{quantized value} $$
  
  Given your example, one can deduce that:
  $$ \text{scale} \approx 0.0077 $$
  $$ \text{zeropoint} = -3 $$
  
  If you actually want to quantize the input value:
  $$ \mathbf{q} = \frac{\mathbf{d}}{\text{scale}} + \text{zeropoint} $$
  
  
  ---
  
  