我已经生成了.onnx模型,但是量化出现了问题,请求帮看下,谢谢!

charlesfan
Posts: 10
Joined: Mon May 20, 2024 6:53 am

我已经生成了.onnx模型,但是量化出现了问题,请求帮看下,谢谢!

Postby charlesfan » Thu May 15, 2025 3:16 am

你好,我量化出了问题帮评估下!
代码:
from tensorflow.lite.python.optimize.calibrator import Calibrator
# Calibration
import tensorflow as tf
import onnx

pickle_file_path = "C:\\data\\pick"
optimized_model_path = output_path
model_proto = onnx.load(optimized_model_path)
print('Generating the quantization table:')

# Initialize an calibrator to quantize the optimized MNIST model to an int16 model using per-tensor minmax quantization method
#calib = Calibrator('int16', 'per-tensor', 'minmax')
calib = Calibrator('int8', 'per-channel', 'entropy')
calib.set_providers(['CPUExecutionProvider'])

# Obtain the quantization parameter
calib.generate_quantization_table(model_proto, calib_dataset, 'mnist_calib.pickle')

# Generate the coefficient files for esp32s3
calib.export_coefficient_to_cpp(model_proto, pickle_file_path, 'esp32s3', '.', 'mnist_coefficient', True)



错误如下:
TypeError Traceback (most recent call last)
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\lite\python\optimize\calibrator.py in __init__(self, model_content, custom_op_registerers_by_name, custom_op_registerers_by_func)
70 model_content, custom_op_registerers_by_name,
---> 71 custom_op_registerers_by_func))
72 self._model_content = model_content

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
1. tensorflow.lite.python.optimize._pywrap_tensorflow_lite_calibration_wrapper.CalibrationWrapper(arg0: handle, arg1: List[str], arg2: List[Callable[[int], None]])

Invoked with: 'int8', 'per-channel', 'entropy'


@Shawn
Espressif staff
Espressif staff
Posts: 17
Joined: Wed Dec 18, 2019 11:15 am

Re: 我已经生成了.onnx模型,但是量化出现了问题,请求帮看下,谢谢!

Postby @Shawn » Thu May 15, 2025 3:48 am

建议使用最新的esp-dl, 参考最新的资料https://docs.espressif.com/projects/esp-dl/en/latest/index.html,里面有mobilenetv2 和 yolo11n 的详细量化过程

Who is online

Users browsing this forum: Bytespider and 1 guest