我已经生成了.onnx模型,但是量化出现了问题,请求帮看下,谢谢!
Posted: 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'
代码:
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'