<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>

CC BY-SA 4.0
2022-07-08T15:39:10.180Z
are you sure about 0.007709330413490534 = 1 / S ? It means S = 1 / 0.007709330413490534 ? I don't understand it
ThoG_Sor
CC BY-SA 4.0
2022-01-05T20:21:02.090Z
2022-01-05T20:21:02.090Z
Amit
<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>

CC BY-SA 4.0
2023-05-10T11:48:30.987Z
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).
Community
CC BY-SA 4.0
2023-05-07T16:43:59.647Z
2023-05-07T16:43:59.647Z
mrtpk
<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>

CC BY-SA 4.0
2024-06-18T12:41:58.493Z
2024-06-18T12:41:58.493Z
Mateusz Koza
<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>

CC BY-SA 4.0
2022-01-04T09:37:42.100Z
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?
nbro
CC BY-SA 4.0
2022-01-04T13:23:41.687Z
I have added the file and edited the title.
Amit
CC BY-SA 4.0
2022-01-04T13:44:17.163Z
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).
nbro
<machine-learning><tensorflow>
Can anyone please explain TFLite quantization part found in Netron neural network viewer?
Amit
# 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 to Netron App website where I have found quantization as below image. Can anyone explain What do the q and 3 mean in Netron quantization?

**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} $$


---

