# Quantization

**URL:** https://community.ultralytics.com/t/quantization/402
**Category:** YOLO
**Tags:** yolo
**Created:** [October 25, 2024, 7:59pm UTC](https://community.ultralytics.com/t/quantization/402 "2024-10-25T19:59:27Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 25, 2024, 7:59pm UTC](https://community.ultralytics.com/t/quantization/402/1 "2024-10-25T19:59:27Z")

</div>

I am trying to run a YOLOv10 model on the NPU of an i.MX8M Plus. After quantization/conversion of the model to best\_full\_integer\_quant.tflite, the model contains operations using int64 typed values I observe using Netron. I get errors when the model is loaded on the device as below:

WARNING: Fallback unsupported op 48 to TfLite  
ERROR: Int64 output is not supported  
ERROR: Int64 input is not supported

What is the procedure to create/convert a YOLOv10 model which does not include operations on int64 typed values.

Thank you

---

<div class="post-metadata">

### Author: ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)
#### Post date: [October 26, 2024, 2:17am UTC](https://community.ultralytics.com/t/quantization/402/3 "2024-10-26T02:17:31Z")

</div>

@ABest2 What library are you using and what’s the command you’re using for export and quantization?

---

<div class="post-metadata">

### Author: ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)
#### Post date: [October 27, 2024, 7:00am UTC](https://community.ultralytics.com/t/quantization/402/4 "2024-10-27T07:00:31Z")

</div>

It should be due to batch normalization parameters.

You can try [this](https://github.com/ultralytics/ultralytics/issues/15026#issuecomment-2296433342) before quantizing. Export the saved `model.pt` you get after running the code

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 28, 2024, 3:26pm UTC](https://community.ultralytics.com/t/quantization/402/5 "2024-10-28T15:26:22Z")

</div>

Hi @BurhanQ,

I am using the following script for export and quantization. I have tried the various combinations of true/false with optimize and simplify with the same result.

Thank you

////////////////////////////////////////////////////////////////////////////////////////////////  
from ultralytics import YOLO

# Load the YOLOv10 model

model = YOLO(“/home/sutter/Desktop/YoloV10-train/runs/detect/train2/weights/best.pt”)

# Export the model to TFLite INT8 format

model.export(format=“tflite”, int8=True, data=‘/home/sutter/Desktop/YoloV10-train/export.yaml’, imgsz=640, optimize=True, simplify=True, nms=False, batch=1, workspace=6.0)  
//////////////////////////////////////////////////////////////////////////////////////////////////

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 28, 2024, 3:28pm UTC](https://community.ultralytics.com/t/quantization/402/6 "2024-10-28T15:28:07Z")

</div>

Hi @Toxite,

I will try what you suggest and update this thread.

Thank you

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 28, 2024, 4:47pm UTC](https://community.ultralytics.com/t/quantization/402/7 "2024-10-28T16:47:57Z")

</div>

Hi @Toxite,

I used the following script prior to export:

/////////////////////////////////////////////////////////////////////////////////////////////////////  
from ultralytics import YOLO

#This must be run in the yoloConvEnv Conda environment using the latest version of Yolo.

model = YOLO()

model = YOLO(‘/home/sutter/Desktop/YoloV10-train/runs/detect/train2/weights/best.pt’)

for m in model.model.model.modules():  
if hasattr(m, “track\_running\_stats”): del m.num\_batches\_tracked

model.ckpt.update(dict(model=model.model))  
del model.ckpt[“ema”]  
model.save(“model.pt”)

/////////////////////////////////////////////////////////////////////////////////////////////////

Unfortunately, the exported version of model.pt was still rejected from the NPU because of the same errors I described before.

Thank you

---

<div class="post-metadata">

### Author: ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)
#### Post date: [October 28, 2024, 7:51pm UTC](https://community.ultralytics.com/t/quantization/402/8 "2024-10-28T19:51:15Z")

</div>

> [@ABest2](#):
>
> the model contains operations using int64 typed values I observe using Netron.

Can you show the name of the layers with int64 operations?

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 28, 2024, 8:30pm UTC](https://community.ultralytics.com/t/quantization/402/9 "2024-10-28T20:30:47Z")

</div>

Hi @Toxite,

I have attached a screenshot of the Find window after searching for int64 within the fully quantized model.

Thank you

 ![Screenshot_Netron](https://us1.discourse-cdn.com/flex001/uploads/ultralytics1/original/1X/38fa79d0316fa850598a18e4f7dd2428d9e6afd8.png)

---

<div class="post-metadata">

### Author: ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)
#### Post date: [October 29, 2024, 10:12am UTC](https://community.ultralytics.com/t/quantization/402/10 "2024-10-29T10:12:20Z")

</div>

Can you check the ONNX graph too and see if INT64 exists?

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 29, 2024, 3:40pm UTC](https://community.ultralytics.com/t/quantization/402/11 "2024-10-29T15:40:52Z")

</div>

Hi @Toxite,

There are many int64 instances in the ONNX model as well.

Thank you

 ![Screenshot_ONNX_Netron](https://us1.discourse-cdn.com/flex001/uploads/ultralytics1/original/1X/79bcd9df8332943fe98b8679c59fe68da8412872.png)

---

<div class="post-metadata">

### Author: ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)
#### Post date: [October 29, 2024, 11:20pm UTC](https://community.ultralytics.com/t/quantization/402/12 "2024-10-29T23:20:11Z")

</div>

You can remove the postprocessing from the model and export.

```python
from ultralytics import YOLO, ASSETS
from ultralytics.nn.modules import Detect

model = YOLO("yolov10n.pt")
for m in model.model.model.modules():                     
    if hasattr(m, "num_batches_tracked"): del m.num_batches_tracked

model.ckpt.update(dict(model=model.model))
if "ema" in model.ckpt: del model.ckpt["ema"]
model.save("model.pt")

model = YOLO("model.pt")
Detect.postprocess = lambda s,x,y,z: x
model.export(format="tflite", int8=True)

```

However, you will have to manually apply the post-processing after inference:

> <https://github.com/ultralytics/ultralytics/blob/886d0c7127301fe52ea3aaeb94bf2a4fa4992baa/ultralytics/nn/modules/head.py#L145>

---

<div class="post-metadata">

### Author: ![ABest2](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@ABest2](https://community.ultralytics.com/u/ABest2)
#### Post date: [October 30, 2024, 7:15pm UTC](https://community.ultralytics.com/t/quantization/402/13 "2024-10-30T19:15:38Z")

</div>

Hi @Toxite,

The model seems to be running on the NPU now as I do not see the int64 error. I need to examine the output tensor now.  
Your help is greatly appreciated!
